-- https://github.com/rime/librime/issues/712#issuecomment-1722225697
-- - lua_processor@*auto_ascii_punct
-- auto_ascii_punct:
-- # - /last_commmit_key/auto_ascii_key/
-- - /%d/,-*+//
-- - /%a/:_-./
-- = /(/)/
-- # - /%a/%a/
-- - /</<>/
local P = {}
-- .....
function P.func(key, env)
local context = env.engine.context
-- ...
if key.keycode < 0x7f and key.keycode > 0x20 then
local latest_text = context.commit_history:latest_text()
if not latest_text or not P.list then
return 2
end
log.error('last_key: ' .. context.commit_history:latest_text() .. " ---------------------")
local ascii_str = string.char(key.keycode)
for k, v in pairs(P.list) do
if latest_text:match("[" .. k .. "]$") and ascii_str:match("[" .. v .. "]") then
return 0
end
end
end
return 2
end
return P
如下脚本:将指定字符后的指定符号切换为 ascii_mode,不清楚哪里出了问题
实际运用中,
看 context.commit_history:latest_text() 的输出发现,由 Shift键 引导的符号(<{()都未能正常获取
输入 ()))) 发现:
输入 []] 是
临时的解决方案是:用 commit_text() 方法,然后 return 1