feat: en_spacer.lua 英文词条上屏自动添加空格 (#496)

This commit is contained in:
xtmu 2023-09-28 23:51:24 +08:00 committed by GitHub
parent 5c9ca84031
commit f935a9c0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

20
lua/en_spacer.lua Normal file
View File

@ -0,0 +1,20 @@
local function add_space_to_english_word(input)
-- 匹配纯英文单词并在单词后添加空格
input = input:gsub("(%a+)", "%1 ")
return input
end
-- 在候选项上屏时触发的函数
function en_spacer(input, env)
for cand in input:iter() do
if cand.text:match("^[%a']+[%a']*$") then
-- 如果候选项是纯英文单词,则在输入后添加一个空格
cand = cand:to_shadow_candidate(cand.type, add_space_to_english_word(cand.text), cand.comment)
end
yield(cand)
end
end
return en_spacer

View File

@ -56,6 +56,10 @@ long_word_filter = require("long_word_filter")
-- 在 engine/filters 增加 - lua_filter@cn_en_spacer
cn_en_spacer = require("cn_en_spacer")
-- 英文词条上屏自动空格
-- 在 engine/filters 增加 - lua_filter@en_spacer
en_spacer = require("en_spacer")
-- 九宫格,手机用。
-- 在 engine/filters 增加 - lua_filter@t9_preedit
t9_preedit = require("t9_preedit")