rime-ice/lua/v_filter.lua
Dvel a34c46ad34 refactor: Lua 模块化
删除 `rime.lua`,拆分到 `lua/` 文件夹内。
方案中的 `- lua_xxx@xxx` 修改为 `- lua_xxx@*xxx`(加一个星号)。
2023-05-05 01:47:05 +08:00

33 lines
1.3 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- v 模式,单个字符优先
-- 因为设置了英文翻译器的 initial_quality 大于 1导致输入「va」时候选项是「van vain …… ā á ǎ à」
-- 把候选项应改为「ā á ǎ à …… van vain」让单个字符的排在前面
-- 感谢改进 @[t123yh](https://github.com/t123yh) @[Shewer Lu](https://github.com/shewer)
local function v_filter(input, env)
local code = env.engine.context.input -- 当前编码
env.v_spec_arr = env.v_spec_arr or Set({"0", "1", "2", "3", "4", "5", "6", "7", "8", "9","Vs."})
-- 仅当当前输入以 v 开头,并且编码长度为 2才进行处理
if (string.len(code) == 2 and string.find(code, "^v")) then
local l = {}
for cand in input:iter() do
-- 特殊情况处理
if (env.v_spec_arr[cand.text]) then
yield(cand)
-- 候选项为单个字符的,提到前面来。
elseif (utf8.len(cand.text) == 1) then
yield(cand)
else
table.insert(l, cand)
end
end
for _, cand in ipairs(l) do
yield(cand)
end
else
for cand in input:iter() do
yield(cand)
end
end
end
return v_filter