mirror of
https://github.com/iDvel/rime-ice.git
synced 2026-05-14 00:30:37 +08:00
chore: clean code
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
-- 英文词条上屏自动添加空格
|
||||
-- 在 engine/filters 的倒数第二个位置,增加 - lua_filter@*en_spacer
|
||||
--
|
||||
-- 英文后,再输入英文单词(必须为候选项)自动添加空格
|
||||
local F = {}
|
||||
|
||||
|
||||
@@ -63,8 +63,6 @@ end
|
||||
|
||||
-- 数值转换为中文
|
||||
local function number2cnChar(num, flag, digitUnit, wordFigure) --flag=0中文小写反之为大写
|
||||
local result = ""
|
||||
|
||||
if tonumber(flag) < 1 then
|
||||
digitUnit = digitUnit or { [1] = "万", [2] = "亿" }
|
||||
wordFigure = wordFigure or { [1] = "〇", [2] = "一", [3] = "十", [4] = "元" }
|
||||
@@ -73,6 +71,7 @@ local function number2cnChar(num, flag, digitUnit, wordFigure) --flag=0中文小
|
||||
wordFigure = wordFigure or { [1] = "零", [2] = "壹", [3] = "拾", [4] = "元" }
|
||||
end
|
||||
local lens = string.len(num)
|
||||
local result
|
||||
if lens < 5 then
|
||||
result = formatNum(num, flag)
|
||||
elseif lens < 9 then
|
||||
|
||||
@@ -126,9 +126,9 @@ function M.init(env)
|
||||
-- 额外处理包含空格的 preedit,增加最后一个拼音的首字母和 zh, ch, sh 的简码
|
||||
if preedit:find(" ") then
|
||||
local preceding_part, last_part = preedit:match("^(.+)%s(%S+)$")
|
||||
local p1, p2 = "", ""
|
||||
local p2 = ""
|
||||
-- p1 生成最后一个拼音的首字母简码拼写(最后一个空格后的首字母),如 ni hao 生成 nih
|
||||
p1 = preceding_part:gsub(" ", "") .. last_part:sub(1, 1)
|
||||
local p1 = preceding_part:gsub(" ", "") .. last_part:sub(1, 1)
|
||||
-- p2 生成最后一个拼音的 zh, ch, sh 的简码拼写(最后一个空格后以 zh ch sh 开头),如 zhi chi 生成 zhich
|
||||
if last_part:match("^[zcs]h") then
|
||||
p2 = preceding_part:gsub(" ", "") .. last_part:sub(1, 2)
|
||||
|
||||
@@ -45,9 +45,7 @@ local function update_dict_entry( s, code, mem, proj )
|
||||
local code_convert = code:sub( i, i + 1 )
|
||||
local p = proj:apply( code_convert, true )
|
||||
if p and #p > 0 then code_convert = p end
|
||||
if code_convert == 'dian' and pos[loop] then
|
||||
-- Ignored
|
||||
else
|
||||
if code_convert ~= 'dian' or not pos[loop] then
|
||||
table.insert( custom_code, code_convert )
|
||||
end
|
||||
loop = loop + 1
|
||||
@@ -283,12 +281,12 @@ function f.func( input, env )
|
||||
end
|
||||
|
||||
-- 上屏其余的候选
|
||||
for i, cand in ipairs( long_word_cands ) do yield( cand ) end
|
||||
if env.show_other_cands then for i, cand in ipairs( other_cand ) do yield( cand ) end end
|
||||
for _, cand in ipairs( long_word_cands ) do yield( cand ) end
|
||||
if env.show_other_cands then for _, cand in ipairs( other_cand ) do yield( cand ) end end
|
||||
end
|
||||
|
||||
function f.tags_match( seg, env )
|
||||
for i, v in ipairs( env.tag ) do if seg.tags[v] then return true end end
|
||||
for _, v in ipairs( env.tag ) do if seg.tags[v] then return true end end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ function select.func(key, env)
|
||||
local selected_candidate = context:get_selected_candidate()
|
||||
selected_candidate = selected_candidate and selected_candidate.text or input
|
||||
|
||||
local selected_char = ""
|
||||
local selected_char
|
||||
if (key:repr() == env.first_key) then
|
||||
selected_char = selected_candidate:sub(1, utf8.offset(selected_candidate, 2) - 1)
|
||||
elseif (key:repr() == env.last_key) then
|
||||
|
||||
@@ -26,8 +26,8 @@ local function unicode(input, seg, env)
|
||||
yield(Candidate("unicode", seg.start, seg._end, text, string.format("U%x", code)))
|
||||
if code < 0x10000 then
|
||||
for i = 0, 15 do
|
||||
local text = utf8.char(code * 16 + i)
|
||||
yield(Candidate("unicode", seg.start, seg._end, text, string.format("U%x~%x", code, i)))
|
||||
local next_text = utf8.char(code * 16 + i)
|
||||
yield(Candidate("unicode", seg.start, seg._end, next_text, string.format("U%x~%x", code, i)))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user