kilocode icon indicating copy to clipboard operation
kilocode copied to clipboard

fix(webview-ui): ignore Enter during IME composition

Open singhvishalkr opened this issue 6 months ago • 6 comments

Context

Issue #7216: with a Chinese IME active, Enter should confirm composition, not send a chat message, pick a model row, commit a rename, or fire other Enter shortcuts. Some paths already checked isComposing; Windows often still reports keyCode === 229 while the IME is handling the key, so Enter could slip through.

Implementation

  • Chat send (PromptInput) and permission / question dock Enter paths now also ignore keyCode === 229.
  • KiloClaw composer (MessageArea), inline message edit (MessageBubble), conversation rename (ConversationList), and sidebar title rename (StatusSidebar) use the same guard.
  • Popup selectors (ModelSelector, ModeSwitcher, ThinkingSelector) only treat Enter as confirm when not in an IME composition.

Screenshots

before after

How to Test

  • On Windows, enable Microsoft Pinyin (or another CJK IME), focus the chat textarea, type a few Latin letters inside composition, press Enter to confirm the composition: the message must not send until you press Enter again in normal typing mode.
  • Repeat in KiloClaw message input and when renaming a conversation title.
  • Open model selector with keyboard, same IME flow: Enter during composition must not select a row.

Get in Touch

Discord same as GitHub profile if maintainers need a repro session.

Fixes #7216

singhvishalkr avatar May 14 '26 13:05 singhvishalkr

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Other Observations (not in diff)

The following files still have Enter key handlers without the IME guard (not touched by this PR — could be a follow-up):

File Line Pattern
src/components/settings/ContextTab.tsx 133 if (e.key === "Enter") addPattern()
src/components/settings/AgentBehaviourTab.tsx 881, 932, 1016 if (e.key === "Enter") addSkillPath/Url/Instruction()
src/components/settings/PermissionEditor.tsx 501 if (e.key === "Enter") submit()
src/components/settings/McpEditView.tsx 177 if (e.key === "Enter") addEnv()
src/components/history/SessionList.tsx 183 if (e.key === "Enter") { ... }
src/components/chat/CloudImportDialog.tsx 53 if (e.key === "Enter") submit()
src/hooks/useFileMention.ts 168 if (e.key === "Enter" || e.key === "Tab")
src/hooks/useSlashCommand.ts 231 if (e.key === "Enter" || e.key === "Tab")
Files Reviewed (13 files)
  • .changeset/ime-enter-composition-guard.md - no issues
  • packages/kilo-vscode/webview-ui/src/utils/ime-enter.ts - no issues
  • packages/kilo-vscode/tests/unit/ime-enter-key.test.ts - no issues
  • packages/kilo-vscode/webview-ui/kiloclaw/components/ConversationList.tsx - no issues
  • packages/kilo-vscode/webview-ui/kiloclaw/components/MessageArea.tsx - no issues
  • packages/kilo-vscode/webview-ui/kiloclaw/components/MessageBubble.tsx - no issues
  • packages/kilo-vscode/webview-ui/kiloclaw/components/StatusSidebar.tsx - no issues
  • packages/kilo-vscode/webview-ui/src/components/chat/PermissionDock.tsx - no issues
  • packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx - no issues
  • packages/kilo-vscode/webview-ui/src/components/chat/QuestionDock.tsx - no issues
  • packages/kilo-vscode/webview-ui/src/components/shared/ModeSwitcher.tsx - no issues
  • packages/kilo-vscode/webview-ui/src/components/shared/ModelSelector.tsx - no issues
  • packages/kilo-vscode/webview-ui/src/components/shared/ThinkingSelector.tsx - no issues

Reviewed by claude-4.6-sonnet-20260217 · 354,453 tokens

Review guidance: REVIEW.md from base branch main

kilo-code-bot[bot] avatar May 14 '26 13:05 kilo-code-bot[bot]

@singhvishalkr please show proof that you tested this manually and it works, thanks

marius-kilocode avatar May 15 '26 15:05 marius-kilocode

@marius-kilocode On the testing ask: the latest push adds webview-ui/src/utils/ime-enter.ts (isEnterKeyCommitNotIme) plus tests/unit/ime-enter-key.test.ts so bun test tests/unit/ime-enter-key.test.ts from packages/kilo-vscode exercises plain Enter, isComposing, and keyCode === 229 on any box that has Bun.

I also loaded the same helper straight from the branch with tsx and checked the three shapes Windows cares about; stdout was:

normal Enter true expect true composing false expect false keyCode229 false expect false OK

Command (cwd packages/kilo-vscode):

npx -y tsx -e "import { isEnterKeyCommitNotIme } from './webview-ui/src/utils/ime-enter.ts'; const a=isEnterKeyCommitNotIme({key:'Enter',isComposing:false,keyCode:13} as KeyboardEvent); const b=isEnterKeyCommitNotIme({key:'Enter',isComposing:true,keyCode:13} as KeyboardEvent); const c=isEnterKeyCommitNotIme({key:'Enter',isComposing:false,keyCode:229} as KeyboardEvent); console.log('normal Enter',a,'expect true'); console.log('composing',b,'expect false'); console.log('keyCode229',c,'expect false'); if(!a||b||c) process.exit(1); console.log('OK');"

All Enter handlers in the PR now call that helper so the unit test is tied to the real import path, not a duplicated condition. For a full IME pass (Pinyin in the sidebar textarea, KiloClaw composer, rename fields, model popup) I still rely on the steps already listed in the PR body on a normal Windows desktop; that part is not something I can record from here, but the 229 branch is what was slipping past isComposing alone and it is now both centralized and covered.

Commit: ab0248a14

singhvishalkr avatar May 15 '26 17:05 singhvishalkr

Still maintaining this PR. Open to rework if maintainers want the patch structured differently before merge.

singhvishalkr avatar May 18 '26 18:05 singhvishalkr

Added a patch changeset for kilo-code (.changeset/ime-enter-composition-guard.md) so the user-facing IME Enter fix is covered for release notes, per kilo-review / AGENTS.md. Pushed afcb1aa5 on fix/7216-ime-enter-submit.

singhvishalkr avatar May 25 '26 16:05 singhvishalkr

Updated this branch against current main.

The merge conflict was only in PromptInput.tsx; I kept the newer review-comment imports and the shared IME helper import. I also formatted PermissionDock.tsx and ime-enter.ts, which were the two files from the previous format:check failure.

Local checks:

  • git diff --check origin/main...HEAD
  • npx.cmd --yes [email protected] --check packages/kilo-vscode/webview-ui/src/utils/ime-enter.ts packages/kilo-vscode/webview-ui/src/components/chat/PermissionDock.tsx

I could not run the Bun package checks locally because Bun is not installed in this Windows shell; GitHub checks are rerunning on 258b8bae1.

singhvishalkr avatar Jun 12 '26 19:06 singhvishalkr

Thanks @singhvishalkr, did a quick brush test seems to work as expected. Sorry for the late reply!

marius-kilocode avatar Jun 17 '26 09:06 marius-kilocode