improve: 改进 v_filter 的性能 (#147)
This commit is contained in:
parent
d859ee255e
commit
58e5a08ac2
13
rime.lua
13
rime.lua
@ -237,6 +237,8 @@ end
|
||||
-- 把候选项应改为「ā á ǎ à …… van vain」,让单个字符的排在前面
|
||||
function v_filter(input, env)
|
||||
local code = env.engine.context.input -- 当前编码
|
||||
-- 仅当当前输入以 v 开头,并且编码长度为 2,才进行处理
|
||||
if (string.len(code) == 2 and string.find(code, "v") == 1) then
|
||||
local l = {}
|
||||
for cand in input:iter() do
|
||||
-- 特殊情况处理
|
||||
@ -246,13 +248,13 @@ function v_filter(input, env)
|
||||
-- 特殊情况处理
|
||||
local arr = { "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣" }
|
||||
for _, v in ipairs(arr) do
|
||||
if (v == cand.text and string.len(code) == 2 and string.find(code, "v") == 1) then
|
||||
if (v == cand.text) then
|
||||
yield(cand)
|
||||
break
|
||||
end
|
||||
end
|
||||
-- 以 v 开头、2 个长度的编码、候选项为单个字符的,提到前面来。
|
||||
if (string.len(code) == 2 and string.find(code, "v") == 1 and utf8.len(cand.text) == 1) then
|
||||
-- 候选项为单个字符的,提到前面来。
|
||||
if (utf8.len(cand.text) == 1) then
|
||||
yield(cand)
|
||||
else
|
||||
table.insert(l, cand)
|
||||
@ -261,6 +263,11 @@ function v_filter(input, env)
|
||||
for _, cand in ipairs(l) do
|
||||
yield(cand)
|
||||
end
|
||||
else
|
||||
for cand in input:iter() do
|
||||
yield(cand)
|
||||
end
|
||||
end
|
||||
end
|
||||
-------------------------------------------------------------
|
||||
-- iRime 九宫格专用,将输入框的数字转为对应的拼音或英文
|
||||
|
Loading…
Reference in New Issue
Block a user