Skip to content

fix(composer): 修复中文输入法下输入斜杠出现 /、 的问题 - #1967

Merged
vastsa merged 1 commit into
vastsa:mainfrom
xuesecanmeng:codex/fix-composer-ime-duplicate-slash
Oct 29, 2026
Merged

vastsa merged 1 commit into
vastsa:mainfrom
xuesecanmeng:codex/fix-composer-ime-duplicate-slash

Conversation

@xuesecanmeng

Copy link
Copy Markdown
Contributor

Fixes #1966

问题

在空白输入框中使用中文输入法按一次 /,最终可能生成 /、,且编辑区 DOM 和草稿状态均包含重复字符。

#1966 报告的环境为 Windows 11、微信输入法 2.1.2。该问题也已在包含 #1248 的上游 main 提交 79fb39b 中隔离复现。

原逻辑在输入法仍处于组合输入阶段时,就将临时文本 、 转换为 /,随后重绘编辑区、替换输入法正在操作的文本节点。输入法最终提交时,可能在已有的 / 后追加 、。

修复

  • 将原生输入事件的 isComposing 传递到草稿处理层,组字期间保留临时文本并继续同步草稿,避免提前转换和重绘。
  • 记录本轮组字开始时草稿是否为空,在组合输入结束后执行开头的斜杠别名转换。
  • 在 compositionend 时读取最终文本和光标位置,确保编辑区 DOM 与草稿状态一致。
  • 在草稿替换、会话或工作区切换时清除旧的组字上下文。
  • 保留 fix(composer): recover the slash menu from a dropped compositionend #1248 对丢失 compositionend 后菜单冻结的恢复逻辑。

修复后,空草稿中的中文输入法斜杠输入最终保留单个 /,并正常触发命令菜单;已有正文中的顿号保持原样。

验证

  • 新增与 [Bug] 空输入框中使用中文输入法按 / 仍生成 /、(#929、#1248 后续) #1966 对应的 Chromium CDP 组合输入回归:先组合输入 、,等待草稿和布局同步,再提交 、。该测试修复前失败,修复后 DOM 与草稿均为单个 /。
  • 覆盖光标位置、普通中文输入、已有文本中的顿号、取消组字及草稿替换。
  • 原有丢失结束事件后的菜单恢复、补全确认路径通过。
  • 68 项相关测试全部通过。
  • 类型检查、生产构建、lint、文档检查、架构检查及上游基线检查通过。
  • 报告者已在 Windows 开发版中手动验证:中文输入法下按 / 不再生成 /、。

Normalizing the leading ideographic comma during pre-edit repaints text
nodes still owned by the IME, allowing its final commit to append a second
character. Preserve pre-edit text and normalize the settled draft while
remembering whether the composition began empty.

Keep missing-compositionend recovery intact and cover the native Chromium
composition sequence, caret position, cancellation, and draft replacement.

@muzimu217 muzimu217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach is the right one for this class of bug: defer the slash-alias conversion until composition ends, and remember whether the draft was empty when the composition started rather than when it finished. That second half is what makes 、 in the middle of existing text stay literal while / at the start still opens the menu, and the draftKey guard on the ref means a session switch mid-composition cannot apply the decision to a different draft.

Driving composition through CDP in scripts/e2e-composer-ime-stack.mjs is the part that makes this reviewable at all — alias commit, ordinary Chinese text, cancellation, draft replacement, completion acceptance and lost-end recovery are exactly the cases a synthetic input event cannot exercise, because the duplicate comes from the IME appending to a text node the app rewrote. Noting in the spec that sending and a physical OS IME stay manual is honest and correct.

One thing I would want to see stated, because it is the ordering that bites in this area: Chromium fires compositionend and then a final input with isComposing === false (some IMEs the other way around). The fix converts at compositionend, so the question is whether that trailing input can re-run the conversion on already-converted text. If the CDP probe asserts the final DOM and draft after the complete compositionstart → input → compositionend → input sequence — which is what a real IME produces — then it is covered and this is just a note for the next reader. If the probe stops at compositionend, adding the trailing input would pin the double-conversion case explicitly.

The isComposing plumbing into onInput(source, start, native.isComposing) is a clean signature change: it keeps the decision at the layer that owns the draft instead of having the input component guess.

@vastsa

vastsa commented Oct 29, 2026

Copy link
Copy Markdown
Owner

独立审查通过,准备合入 915f636dfeb8b52dd1fefbfc1ec073a66eab2ad2。

  • 在当前 main ab7ad4ebe73497ba7d7566b99909fc3e904ee123 的生产组件上重放同一 CDP 输入:组字期间 DOM 提前变为 /,提交后 DOM 和草稿均为 /、,确认 [Bug] 空输入框中使用中文输入法按 / 仍生成 /、(#929、#1248 后续) #1966 仍存在。
  • PR 版本的原生组字、普通中文、正文顿号、取消组字、草稿替换,以及丢失结束事件后的菜单恢复/补全路径通过。另补发组字结束后的非组字 input,最终 DOM/草稿仍为单个 /,光标正确。此次 Chromium 原生序列的最终事件是 compositionend;后置 input 由额外诊断显式补发验证。
  • 本地三个相关测试文件共 23 项通过,git diff --check 通过。远端六项检查全部通过,含构建/类型检查/lint/架构/测试、Rust、Windows 和 Electron E2E。
  • 本机复用依赖中的旧 workspace 声明导致直接桌面类型检查报错;未修改 main 与 PR 的报错逐字一致,因此不把本地类型检查计为通过,也不视为此 PR 的回归。未进行 Windows 实体输入法人工测试。
  • 已重新抓取最新 main;PR head 包含该基线,PR merge ref cf2c712f2bbcf82eb5e55b46023e5b5beaed05a1 与实测 head 的树一致。修复限制在输入/草稿/补全传递及相关测试文档,没有扩大到无关重构。

@vastsa
vastsa merged commit 70b3354 into vastsa:main Oct 29, 2026
6 checks passed
@xuesecanmeng
xuesecanmeng deleted the codex/fix-composer-ime-duplicate-slash branch October 30, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 空输入框中使用中文输入法按 / 仍生成 /、(#929、#1248 后续)

3 participants