diff --git a/lua/aux_code.lua b/lua/aux_code.lua index 8ba4101..b7e4325 100644 --- a/lua/aux_code.lua +++ b/lua/aux_code.lua @@ -83,8 +83,8 @@ function AuxFilter.readAuxTxt(txtpath) local auxCodes = {} for line in file:lines() do if line ~= nil and line ~= "" then -- 检查 line 是否为空 - line = line:match("[^\r\n]+") -- 去掉換行符,不然 value 是帶著 \n 的 - local key, value = line:match("([^=]+)=(.+)") -- 分割 = 左右的變數 + local line_ = line:match("[^\r\n]+") -- 去掉換行符,不然 value 是帶著 \n 的 + local key, value = line_:match("([^=]+)=(.+)") -- 分割 = 左右的變數 if key and value then auxCodes[key] = auxCodes[key] or {} table.insert(auxCodes[key], value) @@ -219,6 +219,7 @@ function AuxFilter.func(input, env) -- 遍歷每一個待選項 for cand in input:iter() do + local cand_ = cand local auxCodes = AuxFilter.aux_code[cand.text] -- 僅單字非 nil local fullAuxCodes = AuxFilter.fullAux(env, cand.text) @@ -236,7 +237,7 @@ function AuxFilter.func(input, env) local shadowText = cand.text local shadowComment = cand.comment local originalCand = cand:get_genuine() - cand = ShadowCandidate(originalCand, originalCand.type, shadowText, + cand_ = ShadowCandidate(originalCand, originalCand.type, shadowText, originalCand.comment .. shadowComment .. '(' .. codeComment .. ')') else cand.comment = '(' .. codeComment .. ')' @@ -246,11 +247,11 @@ function AuxFilter.func(input, env) -- 過濾輔助碼 if #auxStr == 0 then -- 沒有輔助碼、不需篩選,直接返回待選項 - yield(cand) + yield(cand_) elseif #auxStr > 0 and fullAuxCodes and (cand.type == 'user_phrase' or cand.type == 'phrase') and AuxFilter.match(fullAuxCodes, auxStr) then -- 匹配到辅助码的待选项,直接插入到候选框中( 获得靠前的位置 ) - yield(cand) + yield(cand_) else -- 待选项字词 没有 匹配到当前的辅助码,插入到列表中,最后插入到候选框里( 获得靠后的位置 ) -- table.insert(insertLater, cand) diff --git a/lua/cn_en_spacer.lua b/lua/cn_en_spacer.lua index 7d01ea7..5ce5fb1 100644 --- a/lua/cn_en_spacer.lua +++ b/lua/cn_en_spacer.lua @@ -21,10 +21,11 @@ end local function cn_en_spacer(input, env) for cand in input:iter() do + local cand_ = cand if is_mixed_cn_en_num(cand.text) then - cand = cand:to_shadow_candidate(cand.type, add_spaces(cand.text), cand.comment) + cand_ = cand:to_shadow_candidate(cand.type, add_spaces(cand.text), cand.comment) end - yield(cand) + yield(cand_) end end diff --git a/lua/en_spacer.lua b/lua/en_spacer.lua index 293e1ee..26879c7 100644 --- a/lua/en_spacer.lua +++ b/lua/en_spacer.lua @@ -7,11 +7,12 @@ local F = {} function F.func( input, env ) local latest_text = env.engine.context.commit_history:latest_text() for cand in input:iter() do + local cand_ = cand if cand.text:match( '^[%a\']+[%a\']*$' ) and latest_text and #latest_text > 0 and latest_text:find( '^ ?[%a\']+[%a\']*$' ) then - cand = cand:to_shadow_candidate( 'en_spacer', cand.text:gsub( '(%a+\'?%a*)', ' %1' ), cand.comment ) + cand_ = cand:to_shadow_candidate( 'en_spacer', cand.text:gsub( '(%a+\'?%a*)', ' %1' ), cand.comment ) end - yield( cand ) + yield( cand_ ) end end diff --git a/lua/search.lua b/lua/search.lua index 52d5951..d8515d9 100755 --- a/lua/search.lua +++ b/lua/search.lua @@ -21,7 +21,6 @@ local function get_pos( text, char ) local first_char = tmp:sub( 1, utf8.offset( tmp, 2 ) - 1 ) if first_char == char then pos[i] = true end tmp = tmp:gsub( '^' .. first_char, '' ) - i = i + 1 end end return pos