Repository navigation
fix(ui): 输入法组词期间的回车不再触发提交动作 - #481
Merged
Merged
Conversation
The command palette, the project path field and the manual model field ran their action on the Enter that only commits an IME candidate, so a Chinese input either fired the highlighted command or locked in a half-composed value. Guard them the way the composer and the markdown input already do: React does not copy isComposing onto its synthetic keyboard event, so event.nativeEvent is required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
中文输入法选词时按回车是“确认候选词”,但它在三个输入框里同时被当成提交:命令面板会立刻执行高亮命令并收起面板,项目文件夹路径框会把还没写完的路径当成最终值锁定、并用截断的目录名替项目命名,供应商设置的“手动添加模型”会合并半截候选词再清空输入框。三处
onKeyDown都只判event.key === "Enter",没有组合期守卫。补上仓库既有的守卫
event.nativeEvent.isComposing || event.keyCode === 229(lib/composer-keyboard.ts:5、v2/components/markdown-input.tsx:136、v2/components/keyboard-settings.tsx:51、v2/chat-preferences.ts:74,以及命令面板自己的 Ctrl+K 处理都是这个式子)。必须读nativeEvent:React 的SyntheticKeyboardEvent不复制isComposing,写成event.isComposing在浏览器和 jsdom 里都恒为 false,守卫等于没写。这一条是实跑出来的:先用event.isComposing写的版本三条用例全红,换成nativeEvent才变成预期的红/绿。口径:非测试代码里
key === "Enter"/key !== "Enter"判定共 6 处、分布在 5 个文件,修复前缺守卫的是本次这 3 处,修复后 6/6 一致。isComposing与keyCode === 229两个半边都留着:每条用例分别投递isComposing: true和keyCode: 229两种事件,所以两个条件都有实际覆盖,不是冗余死分支。Escape 与方向键在组合期仍不加守卫——它们不执行动作,最坏只是高亮项移动或面板收起,且候选词行为无法在无 WebView2 的环境验证,故不在本 PR 扩大范围。表单原生提交路径(composer 走requestSubmit)不受影响,浏览器在组合期不会用回车提交表单。验证:
origin/main上失败、在本修复后通过:同一组文件旧实现 3 failed / 66 passed,新实现 69 passed。用例断言的是组合期 Enter 不触发动作、面板与路径编辑框保持打开、项目名不被自动派生;{ key: "Enter" }无守卫事件仍照常执行,所以不是把功能一起关掉。npm test全量通过:259 个测试文件 / 2511 项(基线 2508 项 + 本次 3 条)。npm run typecheck、npm run check:api、npm run build通过,git diff --check干净。ocr delegate preview --from origin/main --to HEAD给出 3 个可复核文件 / 共 6 个改动文件(merge_base513c9510,+59/-7),三个.test.tsx被默认路径规则排除,已另行人工复核;三个文件命中ocr delegate rule返回的同一个规则组(system /**/*.{ts,js,tsx,jsx,mjs,cjs}),逐项核对拼写、死代码、硬编码、Hooks 层级与依赖、严格等号、异步错误处理与 XSS/eval 类安全条目,无发现。main的TypeScript console在Audit dependencies步骤上已有红灯(dompurify/@vitest/mocker共 4 条公告,见 fix(ui): 终端关闭响应迟到时保留新的会话绑定 #479 正文的对比记录),本 PR 不含依赖变更,不会让它变好也不会变坏。无 Surface 变化;不含凭据与本地运行数据;不触碰权限、Scope、沙箱与持久化边界;行为修正局限于三个输入框的按键处理,
README.md与项目记忆无需更新。