fix: committed incorrect puncts when user sets non-corresponding keys.
fix: lua hijacked keys when in ascii_mode
fix: handle keys correctly combined with shift
This commit is contained in:
mirtlecn 2024-02-07 16:09:51 +08:00 committed by GitHub
parent 5577c26f1d
commit 1ffdce6a84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 62 additions and 27 deletions

View File

@ -53,8 +53,8 @@ switches:
engine:
processors:
- lua_processor@select_character # 以词定字
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- ascii_composer
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- recognizer
- key_binder
- speller

View File

@ -53,8 +53,8 @@ switches:
engine:
processors:
- lua_processor@select_character # 以词定字
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- ascii_composer
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- recognizer
- key_binder
- speller

View File

@ -53,8 +53,8 @@ switches:
engine:
processors:
- lua_processor@select_character # 以词定字
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- ascii_composer
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- recognizer
- key_binder
- speller

View File

@ -53,8 +53,8 @@ switches:
engine:
processors:
- lua_processor@select_character # 以词定字
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- ascii_composer
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- recognizer
- key_binder
- speller

View File

@ -53,8 +53,8 @@ switches:
engine:
processors:
- lua_processor@select_character # 以词定字
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- ascii_composer
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- recognizer
- key_binder
- speller

View File

@ -53,8 +53,8 @@ switches:
engine:
processors:
- lua_processor@select_character # 以词定字
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- ascii_composer
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- recognizer
- key_binder
- speller

View File

@ -3,36 +3,71 @@
-- 用途示例: `(反引号)被添加到了 speller/alphabet 来响应辅码,如 gan`shuijin 得到「淦」。
-- 这样导致在输入单个的 ` 时仍然需要按空格选择一下。
-- 因为 ` 只在非开头状态下产生作用,所以我希望输入单个的 ` 时和其他标点一样都直接上屏。
local P = {}
function P.get_punct_text(cfg, path)
if cfg:is_list(path) then
-- null value or list -> return nil
-- `: [`,-] -> nil
return nil
elseif cfg:is_map(path) then
local map = cfg:get_map(path)
-- map and has commit key -> return commit text
-- `: {commit: '*'} -> *
-- `: {pair: ["", ""]} -> nil
if map:has_key("commit") then
return map:get_value("commit").value
end
elseif cfg:is_value(path) then
-- string -> return value
-- `: '`' -> `
return cfg:get_string(path)
end
return nil
end
function P.init(env)
P.punct = env.engine.schema.config:get_string(env.name_space:gsub('^*', ''))
local cfg = env.engine.schema.config
P.punct = cfg:get_string(env.name_space:gsub('^*', ''))
if not P.punct then
return
end
local full_shape_path = "punctuator/full_shape/" .. P.punct
local half_shape_path = "punctuator/half_shape/" .. P.punct
P.full_shape_text = P.get_punct_text(cfg, full_shape_path)
P.half_shape_text = P.get_punct_text(cfg, half_shape_path)
end
function P.func(key, env)
local context = env.engine.context
local context = env.engine.context
-- 不影响组合键
if not P.punct or key:release() or key:ctrl() or key:alt() or key:super() or key:shift() then
return 2 -- kNoop
end
-- 不影响组合键
if not P.punct or key:release() or key:ctrl() or key:alt() or key:super() then
return 2 -- kNoop
end
local ascii_str = ''
if key.keycode > 0x20 and key.keycode < 0x7f then
ascii_str = string.char(key.keycode)
end
local ascii_str = ''
if key.keycode > 0x20 and key.keycode < 0x7f then
ascii_str = string.char(key.keycode)
end
-- 解开下面三行,将只允许一次辅码上屏(辅码检索时,将会阻止再次输入辅码)
-- if context.input:find("^[a-z;]+" .. P.char) and ascii_str == P.char then
-- return 1
-- end
-- 解开下面三行,将只允许一次辅码上屏(辅码检索时,将会阻止再次输入辅码)
-- if context.input:find("^[a-z;]+" .. P.char) and ascii_str == P.char then
-- return 1
-- end
if not context:is_composing() and ascii_str == P.punct then
return 0 -- kRejected
end
return 2 -- kNoop
if not context:is_composing() and ascii_str == P.punct then
local is_full_shape = env.engine.context:get_option("full_shape")
if is_full_shape and P.full_shape_text then
env.engine:commit_text(P.full_shape_text)
return 1
elseif (not is_full_shape) and P.half_shape_text then
env.engine:commit_text(P.half_shape_text)
return 1
end
end
return 2 -- kNoop
end
return P

View File

@ -42,8 +42,8 @@ switches:
engine:
processors:
- lua_processor@select_character # 以词定字
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- ascii_composer
- lua_processor@auto_commit_single_punct # 让写在 alphabet 中的某标点自动上屏
- recognizer
- key_binder
- speller