Skip to content

[Bug]: 桌面版对话输入框中文输入法(IME)间断性的无法激活,必须先粘贴中文才能恢复 #150

Open

Description

@u49770008

GUI version

0.1.55

Operating system

Windows

Reproduction steps

  1. 启动 Command Code 桌面版(Windows 11,Microsoft 拼音输入法)。
  2. 点击底部对话输入框(Chat Composer),直接用输入法打字。
  3. 观察:输入法候选框不弹出,中文按键无反应,只能输入英文 —— 「时好时坏」,与输入框获得焦点的时机相关。
  4. 从记事本等处复制几个汉字,切回 Command Code 粘贴到输入框。
  5. 观察:粘贴一完成,输入法立刻被激活,此后可以正常输入中文。
  6. 让输入框再次失焦/重新聚焦,问题可能复现。

Expected behavior

输入框获得焦点后,Windows 中文输入法应直接可用:按键即组字、候选框跟随光标、回车/空格上屏正常,不需要先粘贴任何内容来"激活"输入法。

Actual behavior

焦点落在对话输入框时,Windows IME 与该 textarea 没有正确挂接:候选框不弹出,中文按键被吞掉,只有英文能进。故障是间歇性的,取决于这次聚焦是用户点击还是应用程序化重聚焦。关键指纹:外部粘贴一段中文后 IME 立刻恢复可用 —— 粘贴是一次真实用户手势 + 一次 input 事件,会重建 IME 挂接,而之前那次聚焦没有建立起来。实际影响:每次想写中文都必须在别处打好字再复制粘贴。

Screenshots, recordings, or sanitized logs

版本:Command Code Desktop 0.1.55 / Windows 11 / zh-CN / Microsoft 拼音。Session id: 5ec5254a-700f-40a5-867b-89d1335d3f84

对话输入框是受控 textarea,位于已安装渲染进程包 resources/app/out/renderer/assets/workspace-screen-*.js(组件 ChatComposer,textarea 组件 p5):value 受控,onKeyDown: ta 内部已用 nativeEvent.isComposing 做了组合态保护,Enter 上屏路径本身没问题。

疑似触发点(假设,未定论):焦点管理 hook VW 的 restoreFocus / focusAtEnd 在 requestAnimationFrame 中连续两次调用 textarea.focus() 并随后执行 setSelectionRange()。程序化 focus + setSelectionRange 是 Chromium 上摘除 Windows IME 挂接的常见触发方式,而粘贴是一次真实用户手势会把 IME 重新挂回来,与观察一致。建议排查所有调用 restoreFocus / focusAtEnd 的路径(挂载 useEffect、斜杠命令面板关闭后 onRestoreFocus、附件选择后、提示词历史回溯 focusAtEnd),确认是否在 IME 组合过程中执行了重聚焦/重置选区。

附带小问题:桌面版内置反馈流程 buildFeedbackUrl() 的 platformOption() 只覆盖 macOS/Linux,Windows 下 platform 字段不会被预填。

已排除:非输入框完全不可用(粘贴后同一输入框立即可正常输入中文);非系统输入法问题(同机记事本/浏览器正常);非单一版本回归点,"最后一个可用版本"待确认。

Safety check

  • I removed credentials and private project information from this report.

Activity

  1. added
    p1High priority: blocked workflows, stability, accessibility, or unexpected usage.
    on Oct 22, 2026
  2. self-assigned this
    on Oct 22, 2026
  3. becausemadoka commented on Nov 11, 2026

    @becausemadoka

    0.1.60 和 0.1.61 上仍然可以复现,这个问题没有修好。

    环境:Windows 10(zh-CN),Command Code Desktop 0.1.60 / 0.1.61,用 Windows 安装包安装。

    我在本机测了两个不同的输入法,结果一致:

    • 微软拼音(系统自带)
    • 小狼毫 / Rime

    两者都表现为对话输入框的输入法间歇性失效:有时中文能正常输入;有时聚焦输入框后打字,候选框根本不弹出,按键被吞掉,只有 ASCII 能进去。不是稳定复现的坏,也不是只有微软拼音有问题。失效时,从其他程序粘贴一段中文进同一个 textarea,几乎总能立刻恢复输入法——说明输入框本身没问题,是那一次聚焦没有把 IME 挂接建立起来。

    两个互不相关的输入法(一个微软自带,一个基于 TSF 的第三方)表现完全一样,而同一台机器上记事本和浏览器都正常,所以这更像是应用侧的问题,而不是某个输入法的兼容性问题。

    0.1.61 的 release notes 里没有任何 IME / 组合输入相关条目,这个 issue 的 p1 标签也还在,所以我理解它还没被处理。发这条是为了确认这不是单一版本的回归,并补上版本范围。

    因为是间歇性的,触发点更可能是一个竞态,而不是某条代码路径缺失。一个值得验证的假设:失效可能与输入框如何获得焦点有关,而不是与输入框状态有关。如果直接点击 textarea 与程序化恢复焦点(斜杠命令面板关闭、附件选择器关闭、提示词历史回溯、挂载时的 useEffect)表现不同,那就直接指向原报告里提到的 restoreFocus / focusAtEnd 路径。在 requestAnimationFrame 里先 focus() 再 setSelectionRange(),是 Chromium 上摘掉 Windows IME 挂接的已知方式,也能解释为什么只有真实用户手势才能把它重新挂上。成本较低的缓解方式:isComposing 为 true 时跳过重聚焦和选区重置,或者在选区已经在末尾时不要调用 setSelectionRange。

    如果需要,我可以帮忙测构建版本。


    Still reproducible on 0.1.60 and 0.1.61 — this is not fixed.

    Environment: Windows 10 (zh-CN), Command Code Desktop 0.1.60 and 0.1.61,
    installed via the Windows installer.

    I tested two different IMEs locally, same machine, same result:

    • Microsoft Pinyin (built in)
    • Weasel / Rime (小狼毫)

    In both cases the chat composer loses IME input intermittently: sometimes
    Chinese types normally, sometimes focusing the composer and typing produces no
    candidate window at all — keystrokes are swallowed and only ASCII gets through.
    It is not consistently broken, and it is not specific to Microsoft Pinyin. When
    it is broken, pasting a Chinese string from another app almost always restores
    IME input in the same textarea, so the element itself is fine — it is the IME
    attachment that failed to get established for that particular focus.

    Since two unrelated IMEs (one from Microsoft, one TSF-based third party) fail
    the same way while working normally in Notepad and browsers on the same machine,
    this looks like an app-side issue rather than an IME integration problem.

    The release notes for 0.1.61 have no IME / composition entry, and the p1 label
    is still on this issue, so I assume it has not been worked on yet. Filing this
    to confirm it is not a single-version regression and to add the version range.

    Because it is intermittent, the trigger is probably a race rather than a missing
    code path. One hypothesis worth checking: the failure may correlate with how
    the composer got focus rather than with the composer state. If a direct click
    into the textarea behaves differently from a programmatically restored focus
    (slash-command palette closing, attachment picker closing, prompt-history recall,
    mount useEffect), that points straight at the restoreFocus / focusAtEnd path
    described in the original report. focus() followed by setSelectionRange()
    inside requestAnimationFrame is a known way to detach the Windows IME from a
    Chromium text input, and it would explain why only a real user gesture
    re-attaches it. A cheap mitigation would be to skip the refocus + selection reset
    while isComposing is true, or to avoid calling setSelectionRange when the
    selection is already at the end.

    Happy to test a build if that is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingp1High priority: blocked workflows, stability, accessibility, or unexpected usage.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions