librime-lua
librime-lua copied to clipboard
怎样实现中英文之间自动加空格
考虑以下几种方式
- 在中英混输上屏时,自动在中英文之间加空格
- 在键入任意字符时记录并和上一个字符比对
有哪些接口可能有帮助?
在engine/filters 最後加上一個 lua_filter 檢查前面commit 的字的最後一個 字元不是空白 時 pre_space = " " 候選字是英文時把 候選字 加上空白
local F={}
function F.init(env)
env.size=20
env.history={}
env.notifier= env.engine.context.commit_notifier:connect( function(ctx)
for i=env.size, #env.history do
env.history[i] = nil
end
table.insert( env.history, 1, ctx:get_selected_candidate().text)
end)
end
function F.fini(env)
env.notifier:disconnect()
end
function F.tag_match(seg, env)
-- return env.engine.context:get_option('auto_space") -- 可以加上開關
return true
end
function F.func(inp,env)
local pre_space = ""
if env.history[1] and not env.history[1]:find(" $") then
pre_space= " "
end
for cand in inp:iter() do
if #cand.text == utf8.len(cand.txt) then -- 英文候選加空白
cand.text = pre_space .. cand.text .. " "
end
yield( cand )
end
end
return F
非常感谢!
我在 schema 里最后加上 lua_filter@pangu_filter
在 rime.lua 里加上 local pangu_filter = require("pangu")
新建一个 lua 文件夹,在里面新建 pangu.lua 然后把上面的内容贴进去
重新部署之后遇到问题:任意输入都没有候选词
是否有可能给 select_notifier 传入一个函数,在其中修改即将上屏的候选词?我没翻到相关的接口
可以耶, 測試狀態,但是 大部份 candidate text 是改不了的, 除了 SimpleCandidate
在notifier func 中,加入 engine:commit_text( "--") 會 commit cand 後 commit -- ( 在commit_history 中會增加一個 record type: "raw" text: "--"
你可參考 librime rime/candidate.h librime-lua src/typess.cc CandidateReg set_xxxxx 會檢查 Candidate 型別
然而中英文之间不应该有空格