Repository navigation
fix(terminal): stop Shift+jamo from injecting a newline while an IME composes - #12187
ShreyanshVaibhaw wants to merge 1 commit into
Conversation
…composes `isTerminalImeProcessEnter` matched any key reported as `Process` with keyCode 229 and a lone Shift or Ctrl. While a Windows IME composes, that description fits every key, not just Enter, so Shift+<jamo> on the Korean 2-beolsik layout (the double consonants ㄸ/ㄲ/ㅆ/ㅉ/ㅃ) matched too. keyboard-handlers then synthesizes `key: 'Enter'` for anything that matches and hands it to the shortcut resolver, so typing a double consonant fired the Shift+Enter newline shortcut mid-word. Plain Shift+letter is unaffected because English input is not IME-composed and reports its real key. Require the physical key to be Enter or NumpadEnter. `code` is unaffected by composition, so it separates a real Shift+Enter from a composed jamo without changing the Shift+Enter path. Fixes stablyai#11878
Greptile SummaryThis PR fixes a stray newline injected mid-word when typing Korean double consonants (ㄸ ㄲ ㅆ ㅉ ㅃ) in a Windows terminal pane with an active IME composition. The root cause was that
Confidence Score: 5/5Safe to merge. The change is a single additional guard in one predicate, and the only caller is already gated behind isWindows && hasPendingImeComposition, so macOS and Linux are unaffected. The fix is minimal and precisely targeted: one extra boolean condition that correctly uses event.code — a property unaffected by IME composition — to distinguish a physical Enter from any other composed key. The test factory was correctly updated to default code: 'Enter', so the existing positive assertions still validate what they claim. The five new regression cases cover every 2-beolsik double consonant, and the NumpadEnter positive case ensures that path is explicitly pinned rather than accepted incidentally. No logic outside this predicate is touched. Files Needing Attention: No files require special attention. The call site in keyboard-handlers.ts already reads e.code on the line immediately after the predicate call, so code is present on every event that reaches this path.
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts | Adds code to the isTerminalImeProcessEnter Pick type and gates the function on `event.code === 'Enter' |
| src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts | Adds code: 'Enter' default to the shared test factory (preventing vacuous passes against the new condition), adds a NumpadEnter positive case, and adds five 2-beolsik regression cases (KeyE/KeyR/KeyT/KeyW/KeyQ) that each confirm the fix rejects jamo keystrokes mid-composition. |
Sequence Diagram
sequenceDiagram
participant OS as Windows IME
participant Browser as Chromium
participant KH as keyboard-handlers.ts
participant IIPE as isTerminalImeProcessEnter
participant SR as Shortcut Resolver
Note over OS, SR: Before fix — Shift+ㄸ (KeyE) during composition
OS->>Browser: "keydown: key='Process', keyCode=229, code='KeyE', shiftKey=true"
Browser->>KH: keydown event
KH->>IIPE: isTerminalImeProcessEnter(e) — only checked key, keyCode, modifier
IIPE-->>KH: true ❌ (false positive)
KH->>SR: "synthetic {key:'Enter', shiftKey:true}"
SR-->>KH: fires Shift+Enter → newline injected mid-word
Note over OS, SR: After fix — Shift+ㄸ (KeyE) during composition
OS->>Browser: "keydown: key='Process', keyCode=229, code='KeyE', shiftKey=true"
Browser->>KH: keydown event
KH->>IIPE: isTerminalImeProcessEnter(e)
Note right of IIPE: code='KeyE' ≠ 'Enter' → short-circuits to false
IIPE-->>KH: false ✅
KH->>SR: original event passed through
SR-->>KH: normal jamo character typed
Note over OS, SR: After fix — genuine Shift+Enter during composition
OS->>Browser: "keydown: key='Process', keyCode=229, code='Enter', shiftKey=true"
Browser->>KH: keydown event
KH->>IIPE: isTerminalImeProcessEnter(e)
Note right of IIPE: code='Enter' ✓ → getTerminalImeModifiedEnterKind → 'shift'
IIPE-->>KH: true ✅
KH->>SR: "synthetic {key:'Enter', shiftKey:true}"
SR-->>KH: Shift+Enter newline sent correctly
Reviews (1): Last reviewed commit: "fix(terminal): stop Shift+jamo from inje..." | Re-trigger Greptile
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 587f5c3e-cc79-4365-be81-6fefd96ec921
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts
| // Why: while an IME composes, Windows reports key 'Process' and keyCode 229 for | ||
| // every key, not just Enter. Without the physical key, Shift+<jamo> (the 2-beolsik | ||
| // double consonants ㄸ/ㄲ/ㅆ/ㅉ) is indistinguishable from Shift+Enter and gets | ||
| // rewritten into a newline. `code` survives composition and identifies the key. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Keep the Korean double-consonant rationale complete.
Both comments omit ㅃ, although the regression tests cover all five consonants. Add ㅃ to both comments.
- src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts#L118-L121: add
ㅃto the source rationale. - src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts#L358-L360: add
ㅃto the regression comment.
📍 Affects 2 files
src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts#L118-L121(this comment)src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts#L358-L360
Confirmed on a real Windows + 2-beolsik setupYou asked for confirmation from a reporter on a real Korean IME before merge — here it is. Setup
Result: the spurious newline is gone. Typing Shift-requiring jamo (쌍자음 and ㅒ/ㅖ — e.g. I'm the reporter of #12156, which you listed as a likely duplicate — that's correct, same root cause, and the newline half of it is fixed here. One note on #12156 specifically: that issue also reports a second symptom — triggering the bug twice in a row additionally copies the in-progress terminal input line to the OS clipboard (verified by pasting into Notepad, with "copy on select" and OSC 52 both off). I have not yet re-tested that specific two-in-a-row clipboard case against this branch, so I can't confirm whether this fix covers it too. Given the newline no longer fires at all, it plausibly does — but worth someone verifying rather than assuming, since the clipboard write path was never fully traced in that issue. Unrelated build note, in case it helps other Windows contributors: Thanks for the quick turnaround on this one. |
|
Closing as superseded by #12265, which landed the Shift+jamo/non-Enter Process-key fix with the broader Windows IME ownership and press-evidence coverage. Thank you for the focused diagnosis and tests. |
Summary
Fixes #11878.
Typing Korean double consonants (ㄸ ㄲ ㅆ ㅉ ㅃ) in a Windows terminal pane injected a stray newline mid-word, as if Enter had been pressed partway through typing.
isTerminalImeProcessEnteridentified a composed Shift+Enter as "key isProcess, keyCode is 229, exactly one of Shift or Ctrl held":While a Windows IME composes, that description fits every key, not just Enter. On the 2-beolsik layout each double consonant is Shift + a base key, so it matched.
keyboard-handlers.tsthen synthesizeskey: 'Enter'for anything that matches and hands it to the shortcut resolver:So typing ㄸ fired the Shift+Enter newline shortcut. This matches the isolation in the linked reports exactly: plain Shift+letter is fine, because English input is not IME-composed and reports its real key.
The fix requires the physical key to actually be Enter.
codeis unaffected by composition, so it separates a genuine Shift+Enter from a composed jamo without touching the Shift+Enter path itself.codewas already being read one line later, it just was not part of the test.Likely duplicates
Several recent reports appear to share this cause. Worth a triage pass rather than my assertion:
#12179, #12156, #12152, #12151, #12184
I did not include #12164 (IME syllable duplication in rendering) or #12171 (macOS Korean input latency). Those look like different code paths and I have not verified them.
Screenshots
No visual change.
Testing
pnpm lint(one pre-existing unrelated failure, see Notes)pnpm typecheckpnpm test(full suite does not pass on this machine before or after, see Notes)pnpm build(not run locally)Added regression tests
src/renderer/src/components/terminal-pane/: 2892 passed, 218 files, 0 failedNew cases cover all five 2-beolsik double consonants by physical
code, plus NumpadEnter to keep the real Shift+Enter path covered.Confirmed to fail against the previous implementation: reverting the source fails exactly the 5 new jamo cases and nothing else.
Verification caveat, stated plainly
I do not have a Korean IME on Windows and could not reproduce the original symptom first-hand. This fix was derived from reading the input path and is verified by tests and by the reporters' own isolation (single Shift+key fine, consecutive ones break; English Shift unaffected), not by observing the bug. Confirmation from any of the reporters on a real 2-beolsik setup would be worth having before merge.
AI Review Report
Reviewed with Claude. Risks checked:
isWindows && hasPendingImeComposition. macOS and Linux never reach it. No platform branch added or removed.code === 'Enter'and now also explicitly forNumpadEnter, which the previous predicate accepted only incidentally. A test pins that.Process/229 get the same correction. Nothing in the change is layout-specific.code, which would have made every existing case pass vacuously against the new condition. The factory now defaultscode: 'Enter', so the existing assertions still mean what they claim.Security Audit
Notes
pnpm lintfails atverify:skill-bundle-manifestwith staleresources/skills/*.json. Reproduces on a cleanmain, so it is not introduced here, and those are generated artifacts I did not want to churn.pnpm testandpnpm buildnot completed locally. A cleanmainon this Windows machine fails 167 tests across 57 files, so a green local suite is not achievable either way. The affected area is fully green.--resumeargument arriving as literal typed text after a restart. That is a different mechanism (session replay, not key handling) and is not addressed here.