Skip to content

Ctrl+Space 切换中英文时丢弃当前编码,无法原码上屏 #1843

@ocherry341

Description

@ocherry341

问题描述

正在输入编码(比如 nihao)时,按 Ctrl+Space 切到英文模式,期望当前编码 nihao 作为英文原样上屏,然后进入 ascii_mode。这是传统中文输入法(搜狗、QQ、微软拼音等)的常见行为。

目前 Weasel 的实际行为是:nihao 被直接丢弃,只切换了模式。

而且这个行为没法通过用户配置改变——default.yaml 里的 ascii_composer/switch_keycommit_code 等语义)和 key_binder/bindings/Control+space 都对 Ctrl+Space 无效。

原因

Ctrl+Space 在 Windows 下触发的是 TSF 的 GUID_COMPARTMENT_KEYBOARD_OPENCLOSE 信号,由 WeaselTSF/Compartment.cpp::_HandleCompartment 处理,这条路径完全绕过了 librime 的键盘事件管线,所以 ascii_composer 的配置根本不会被执行。

该函数目前只有两种分支(由注册表 HKCU\Software\Rime\weasel\ToggleImeOnOpenClose 控制):

行为
"yes" ClearComposition() + _EndComposition(),真正关闭 IME
"no"(默认) ClearComposition() + 翻转 _status.ascii_mode

两种分支都调 ClearComposition,没有 commit 的选项。

期望行为

按 Ctrl+Space 时,当前未确认的编码能原样上屏,再翻转 ascii_mode——等价于 librime ascii_composer 里已有的 commit_code 语义(kAsciiModeSwitchCommitCode,见 src/rime/gear/ascii_composer.cc),只是当前从 TSF compartment 路径进入时触达不到。

相关代码位置

  • WeaselTSF/Compartment.cpp::_HandleCompartment (~line 244–278)
  • WeaselTSF/WeaselTSF.cpp::OnSetThreadFocus (~line 174):ToggleImeOnOpenClose 读取
  • RimeWithWeasel/RimeWithWeasel.cpp::CommitComposition / ClearComposition
  • librime src/rime/gear/ascii_composer.cc::SwitchAsciiMode(已存在的 commit_code 实现)

环境

  • Weasel: 0.17.4
  • Windows 11
  • 已确认 default.yamlascii_composer/switch_keykey_binder/bindings/Control+space 均对 Ctrl+Space 无效

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions