rime / squirrel

【鼠鬚管】Rime for macOS
https://rime.im
GNU General Public License v3.0
4.64k stars 411 forks source link

[Bug] 触发 set_option ascii_mode 时无法通过配置 ascii_composer 直接上屏 #957

Closed scturtle closed 3 months ago

scturtle commented 3 months ago

簡要描述 Bug:

default.custom.yaml 配置:

patch:
  schema_list:
    - schema: double_pinyin
  ascii_composer/switch_key/+:
    Control+Shift+space: commit_code
  key_binder/bindings:
    - { when: always, accept: Control+space, unset_option: ascii_mode }
    - { when: always, accept: Control+Shift+space, set_option: ascii_mode }

当用中文输入若干字符之后:

image

用快捷键触发 set_option ascii_mode 切换到英文:

image

会保留 inline_preedit 状态,此时需要回车才会上屏:

image

且配置了 ascii_composer 中相同的快捷键也无效。

預期行爲:

可控制 set_option ascii_mode 时上屏。

實際行爲:

无法控制 set_option ascii_mode 时是否上屏,保留 inline_preedit 状态。

環境

我試過:

scturtle commented 3 months ago

看了下 librime 的代码,似乎是 AsciiComposer::ProcessKeyEvent 只识别特定按键序列才调用 ToggleAsciiModeWithKey

scturtle commented 1 month ago

找到办法了,用 lua 监听一下 set_option ascii_mode 事件然后上屏。

local f = {}
function f.init(env)
    context = env.engine.context
    context.option_update_notifier:connect(function(ctx, name)
        if name == "ascii_mode" and ctx:get_option("ascii_mode") then
            context:clear_non_confirmed_composition()
            context:commit()
        end
    end)
end
return f