Skip to content

fix(terminal): stop Shift+jamo from injecting a newline while an IME composes - #12187

Closed
ShreyanshVaibhaw wants to merge 1 commit into
stablyai:mainfrom
ShreyanshVaibhaw:fix/ime-shift-composition-false-enter
Closed

ShreyanshVaibhaw wants to merge 1 commit into
stablyai:mainfrom
ShreyanshVaibhaw:fix/ime-shift-composition-false-enter

Conversation

@ShreyanshVaibhaw

Copy link
Copy Markdown

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.

isTerminalImeProcessEnter identified a composed Shift+Enter as "key is Process, keyCode is 229, exactly one of Shift or Ctrl held":

event.key === 'Process' && event.keyCode === 229 && getTerminalImeModifiedEnterKind(event) !== null

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.ts then synthesizes key: 'Enter' for anything that matches and hands it to the shortcut resolver:

const imeProcessEnter = isWindows && hasPendingImeComposition && isTerminalImeProcessEnter(e)
const shortcutEvent = imeProcessEnter ? { key: 'Enter', code: e.code, ... } : e

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. code is unaffected by composition, so it separates a genuine Shift+Enter from a composed jamo without touching the Shift+Enter path itself. code was 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 typecheck

  • pnpm 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 failed

  • New 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:

  • Cross-platform. The only caller is already gated behind isWindows && hasPendingImeComposition. macOS and Linux never reach it. No platform branch added or removed.
  • Does not narrow the real Shift+Enter path. The synthesized-Enter branch still triggers for code === 'Enter' and now also explicitly for NumpadEnter, which the previous predicate accepted only incidentally. A test pins that.
  • Other IMEs. The fix keys on the physical key rather than on anything Korean-specific, so Japanese and Chinese IMEs that also report Process/229 get the same correction. Nothing in the change is layout-specific.
  • Flagged and addressed. The review noted the shared test factory omitted code, which would have made every existing case pass vacuously against the new condition. The factory now defaults code: 'Enter', so the existing assertions still mean what they claim.

Security Audit

  • Input handling. This strictly narrows which key events are rewritten into a synthetic Enter. No input is newly trusted or forwarded.
  • Command execution, path handling, auth, secrets, IPC, dependencies. Untouched. No dependency changes.
  • No user-controlled string reaches a shell, filesystem, or network path from this code.

Notes

  • Pre-existing lint failure. pnpm lint fails at verify:skill-bundle-manifest with stale resources/skills/*.json. Reproduces on a clean main, so it is not introduced here, and those are generated artifacts I did not want to churn.
  • pnpm test and pnpm build not completed locally. A clean main on 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.
  • Scope held deliberately narrow. [Bug]: Typing a Hangul syllable whose batchim (final consonant) requires Shift inserts a stray newline in Claude Code #12179 also mentions a --resume argument arriving as literal typed text after a restart. That is a different mechanism (session replay, not key handling) and is not addressed here.

…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-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown

Greptile Summary

This 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 isTerminalImeProcessEnter identified any key as a composed Enter by checking only key === 'Process', keyCode === 229, and a Shift/Ctrl modifier — a description that Windows IME satisfies for every key during composition, not just Enter.

  • Source fix (terminal-ime-deferred-newline.ts): adds code to the function's Pick type and short-circuits on event.code === 'Enter' || event.code === 'NumpadEnter', using the physical key identity that survives IME composition to distinguish a real Enter from a composed jamo.
  • Test changes (terminal-ime-deferred-newline.test.ts): adds code: 'Enter' as the factory default (preventing existing tests from passing vacuously against the new check), adds a NumpadEnter positive case, and adds five 2-beolsik regression cases — one per double consonant physical key — each confirmed to fail against the pre-fix implementation.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "fix(terminal): stop Shift+jamo from inje..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

isTerminalImeProcessEnter now checks KeyboardEvent.code and accepts only Enter or NumpadEnter with the existing IME conditions. Tests include the Enter code, verify composing NumpadEnter handling, and reject shifted Korean 2-beolsik composition keystrokes.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the terminal IME bug fix and identifies the affected Shift+jamo behavior.
Description check ✅ Passed The description includes all required sections, testing details, review findings, security audit, and explanations for incomplete checks.
Linked Issues check ✅ Passed The code requires Enter or NumpadEnter before IME rewriting, preventing Korean double consonants from becoming newlines while preserving genuine Enter handling [#11878].
Out of Scope Changes check ✅ Passed The source and test changes are limited to the linked Windows IME newline issue and its regression coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 922268a and e79c969.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts

Comment on lines +118 to +121
// 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.

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.

📐 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

@USERNAME-737

Copy link
Copy Markdown

Confirmed on a real Windows + 2-beolsik setup

You asked for confirmation from a reporter on a real Korean IME before merge — here it is.

Setup

  • Windows 10 Enterprise 19045
  • Microsoft Korean IME, 2-beolsik (두벌식)
  • Built and ran this branch (fix/ime-shift-composition-false-enter) as a dev instance via pnpm dev, alongside the installed production 1.4.164 that still reproduces the bug.

Result: the spurious newline is gone. Typing Shift-requiring jamo (쌍자음 and ㅒ/ㅖ — e.g. 있다, 했다, 얘기, 오빠) in a terminal pane no longer injects a line break mid-word. Same keystrokes on production 1.4.164 reproduce it every time.

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: pnpm install / pnpm dev hard-fails on a machine without Visual Studio Build Tools because windows-native-registry can't be rebuilt (ensure-native-runtime.mjs gates startup on it). It's only used by src/main/cli/windows-user-path-registry.ts, which already handles failure via try/catch. Adding it to the existing ignoreModules list let the dev build run fine. Not related to this PR — just a hurdle for anyone trying to verify Windows IME fixes locally.

Thanks for the quick turnaround on this one.

@nwparker

nwparker commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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.

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]: Korean double consonants (쌍자음) trigger automatic line breaks in the Windows integrated terminal

3 participants