Skip to content

[P1] fix(terminal): require a physical Enter for Windows IME process-enter - #11616

Closed
nwparker wants to merge 2 commits into
mainfrom
nwparker/p1-windows-ime-process-enter
Closed

nwparker wants to merge 2 commits into
mainfrom
nwparker/p1-windows-ime-process-enter

Conversation

@nwparker

@nwparker nwparker commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • On Windows, Chromium reports every key an active IME consumes as key='Process'/keyCode=229, so isTerminalImeProcessEnter matched any modified IME-consumed key, not just Enter.
  • Shift+<jamo> (e.g. Shift+KeyQ for ㅃ) or an MS-IME Ctrl chord (Ctrl+KeyI) was misread as Shift/Ctrl+Enter; keyboard-handlers.ts then synthesized an Enter event and terminal-shortcut-policy.ts injected \x1b\r / \x1b[13;5u into the shell.
  • Fix: isTerminalImeProcessEnter now also requires the physical key code to be Enter or NumpadEnter, which Chromium reports faithfully even when the IME consumes the key.
  • No other behavior changed; the synthesized-event path in keyboard-handlers.ts already forwards the original event with its .code.

Test plan

  • Extended terminal-ime-deferred-newline.test.ts unit cases: rejects code: 'KeyQ' (shift) and code: 'KeyI' (ctrl), accepts code: 'Enter' and code: 'NumpadEnter' for both shift and ctrl kinds.
  • Extended the Windows IME harness in keyboard-handlers-ime.test.tsx: IME-consumed Shift+KeyQ / Ctrl+KeyI during composition are not swallowed and send no input; Process+code Enter/NumpadEnter still defers and sends \x1b\r after composition (regression guard for fix(terminal): reconcile cross-platform IME composition lifecycle #11293).
  • Verified the new tests fail on the unfixed code (git stash of the production change): 4 failures, e.g. does not treat an IME-consumed 'Shift+KeyQ' as a modified Enter — AssertionError: expected true to be false on defaultPrevented; all 45 tests pass with the fix restored.
  • Ran all dependent test files (xterm-bypass-policy, keyboard-handlers, terminal-ime-deferred-newline, keyboard-handlers-ime, terminal-pane-split-writer-paths): 94 passed. npx oxlint and tsc -p config/tsconfig.tc.web.json clean.

Found by the production release scan of v1.4.162..v1.4.163-rc.0.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: af1103fa-1c2d-4439-a16d-fcb19ce6e67f

📥 Commits

Reviewing files that changed from the base of the PR and between d0d7e77 and 9f449d7.

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

📝 Walkthrough

Walkthrough

The IME utilities now distinguish consumed Process/229 keys from deferred physical Enter and NumpadEnter events. The keyboard handler filters consumed non-Enter keys before shortcut resolution and propagation, while composed Enter events remain deferred and send \x1b\r. Tests cover modifier combinations, non-Enter rejection, terminal input, pane shortcuts, and window-level handlers.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix and testing well but omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, including no-visual-change confirmation, AI review and cross-platform checks, security audit findings, and platform-specific notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Windows IME fix and the requirement for a physical Enter key.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a Windows IME bug where any IME-consumed key (reported as Process/keyCode 229) with a Shift or Ctrl modifier was incorrectly treated as a modified Enter, causing spurious \x1b\r / \x1b[13;5u sequences to be injected into the shell. The fix tightens isTerminalImeProcessEnter to additionally require event.code === 'Enter' || event.code === 'NumpadEnter', and adds a second guard in the keyboard handler to stopImmediatePropagation() on all other IME-consumed keys during composition.

  • isTerminalImeConsumedKey is extracted as a shared helper used by both the Enter-detection path and the new swallow-all-other-IME-keys guard.
  • isTerminalImeProcessEnter now requires the physical code to be Enter or NumpadEnter, preventing false positives for keys like Shift+KeyQ (Korean ㅃ) or Ctrl+KeyI.
  • New unit and integration tests cover rejection of KeyQ/KeyI chords, NumpadEnter acceptance, no spurious sendInput or pane-shortcut invocations, window-level handler suppression, and a regression guard for the Shift+Enter deferred-send path.

Confidence Score: 5/5

Safe to merge — the fix is narrowly scoped to Windows IME composition and all existing and new tests pass.

The change makes a precise, well-bounded correction: it adds a physical key-code check to a single predicate and a matching stopImmediatePropagation guard. The happy paths (Shift+Enter, Ctrl+Enter deferred newline) are covered by regression tests, and the previously-broken paths (Shift+KeyQ, Ctrl+KeyI, Ctrl+KeyK, Ctrl+KeyW during composition) now have explicit test coverage. No logic outside the Windows IME composition path is touched.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts Extracts isTerminalImeConsumedKey as a named helper and adds a code guard to isTerminalImeProcessEnter so only 'Enter'/'NumpadEnter' physical keys are treated as IME-Enter; the empty-code fallback path is explicitly documented.
src/renderer/src/components/terminal-pane/keyboard-handlers.ts Adds a guard that calls stopImmediatePropagation() for any Windows IME-consumed non-Enter key during composition, preventing Ctrl+K/Ctrl+W and window-level shortcuts from misfiring mid-IME.
src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts Adds code: 'Enter' as default in the event factory and extends rejection cases with KeyQ and KeyI; NumpadEnter acceptance cases added for both shift and ctrl paths.
src/renderer/src/components/terminal-pane/keyboard-handlers-ime.test.tsx Exposes sendInput mock on the harness and adds three new integration test groups: non-Enter IME chords don't trigger sendInput or pane shortcuts, window-level handlers don't see swallowed Ctrl chords, and Shift+Enter still defers correctly via both Enter and NumpadEnter codes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Windows keydown during IME composition] --> B{isTerminalImeConsumedKey\nkey=Process and keyCode=229}
    B -- No --> F[Normal shortcut resolution]
    B -- Yes --> C{code is Enter or NumpadEnter}
    C -- Yes with shift or ctrl --> D[Synthesize Enter event\nDefer send after compositionend]
    C -- No --> E[stopImmediatePropagation\nReturn, no shortcut fires]
    D --> G[sendInput after composition ends]
    E --> H[IME composition continues uninterrupted]
Loading

Reviews (2): Last reviewed commit: "fix(terminal): keep IME-consumed Process..." | Re-trigger Greptile

@BaeTab

BaeTab commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Confirming this on Windows 11 + Microsoft 두벌식 (2-set Korean), Orca v1.4.163. I hit it during normal typing, not while testing edge cases.

Scope is wider than double consonants

2-set Korean needs Shift for seven jamo, and all seven reproduce:

Jamo Chord
ㅃ ㅉ ㄸ ㄲ ㅆ Shift + Q/W/E/R/T
ㅒ ㅖ Shift + O/P

The two vowels (ㅒ ㅖ) reproducing is the useful part: they go through different composition logic than the consonants, so this rules out anything jamo-specific and pins it to the modifier-flag-only check — exactly what this PR fixes. Any framing of this as a "double consonant" bug is too narrow.

Words that hit it constantly: 있다, 했다, 갔다, 됐다, 예를 들어, 얘기, 오빠, 예쁘다.

It only fires when the Shift-jamo lands mid-word (a composition is already pending), consistent with the hasPendingImeComposition condition at keyboard-handlers.ts:502.

Both halves of the symptom

  1. A newline is injected — terminal-shortcut-policy.ts:188 → \x1b\r.
  2. The jamo itself is swallowed — keyboard-handlers.ts:529 stopImmediatePropagation().

Reading the diff, this PR addresses both: the predicate change stops the synthesized Enter (so preventDefault never runs), and the new swallow branch calls stopImmediatePropagation() without preventDefault, so the IME still composes.

The red CI is an infrastructure flake

Worth flagging since this is P1 and currently reads as broken:

node-pty install: gyp ERR! stack AggregateError [ETIMEDOUT]
[native-runtime] pnpm rebuild node-pty failed.

tests node 24 10/16 failed inside pnpm rebuild node-pty — no test executed; the whole 1m30s was dependency install. verify is only the aggregator job (pr.yml:376) and is red solely because of that shard.

The same shard on Node 26 passed, as did the other 31 shards, static analysis, typecheck, package, and the Linux X11 IBus IME suite. A re-run should clear it.

Possible collision with #11550

#11550 edits the same lines of isTerminalImeProcessEnter with a semantically identical code === 'Enter' || 'NumpadEnter' requirement, derived from Microsoft Pinyin traces. Whichever lands first will force the other to rebase.

One thing worth preserving from this PR: #11550 does not include the swallow branch for IME-consumed chords, so Ctrl+K / Ctrl+W mid-composition would still resolve through the physical-code fallback in terminal-shortcut-policy.ts:285-318.

Related issue

I filed #11878 for this before finding this PR. Note that the "Likely code path" section in that issue is wrong — it blames a stale heldImeEnterModifiers Shift being attributed to a later plain Enter. The ㅒ/ㅖ result above disproves that, and the newline appears without any Enter being pressed. This PR's diagnosis is the correct one. I'll correct that issue.

Two questions, not objections

  1. code === '' — the comment notes a key event without a scan code falls back to the Enter keyup path. Some RDP/VNC clients and on-screen keyboards report an empty code; would those lose the composing Shift+Enter deferral they have today? I don't see a test covering it.
  2. Plain composing Enter — it now takes the new swallow branch rather than falling through. The rationale ("xterm already ignores keyCode 229 while composing") holds while xterm's _isComposing and Orca's hasPendingTerminalImeComposition agree — is there a case where they diverge?

I have the setup to capture a full native event trace (window-capture keydown/keyup + composition events, including code) and a cat -v recording showing the injected ^[^M. I'll follow up with those. Happy to add the ㅒ/ㅖ cases to keyboard-handlers-ime.test.tsx if that's useful.

@holdn2

holdn2 commented Aug 2, 2026

Copy link
Copy Markdown

Heads up — I've opened #12120 as a draft that carries both of your commits here
(d0d7e77 physical-Enter classification, 9f449d7 the shortcut propagation guard)
with --author preserved, alongside the minimum hunks from #11937, #11896 and #11870.

The reason for bundling: each of the four PRs closes one event path, but a user typing
빨래 hits several in one composition. I added a regression test for that exact sequence —
a Shift-jamo consumed as Process/229, the committing Enter after it, then the rollover
Shift — which fails on main and needs your classification fix and #11937's keyup gate
to pass.

This is not meant to supersede your PR, and I'd be glad if maintainers just landed yours.
Say the word and I'll close mine. Any correction on how I've represented your work is welcome.

@dpfwpfahs1-coder

Copy link
Copy Markdown

Still reproduces on v1.4.164, the current latest release — so no shipped build fixes this yet.

Environment

  • Windows 11 Pro 10.0.26200
  • Orca 1.4.164 (updated and restarted; running process confirmed on 1.4.164)
  • Microsoft Korean IME, 2-set / 두벌식

Symptom
Typing a Shift-jamo (e.g. ㄸ = Shift+E) during ordinary Hangul input in a terminal agent session submits a newline I never typed. This shows up in normal day-to-day work, not while probing edge cases.

Adding this mainly as a version data point rather than new analysis: v1.4.163 already shipped the IME composition integration from #11293, and v1.4.164 is the current release, so the isTerminalImeProcessEnter path this PR targets is still reachable in released builds.

The diagnosis here — and in the Greptile summary above — matches exactly what I see. Nothing to add to it. Just flagging that it is hitting real users on the current release, and that this PR has had no review since 2026-07-30.

holdn2 pushed a commit to holdn2/orca that referenced this pull request Aug 3, 2026
holdn2 pushed a commit to holdn2/orca that referenced this pull request Aug 3, 2026
holdn2 pushed a commit to holdn2/orca that referenced this pull request Aug 3, 2026
A Shift-jamo consumed as Process/229, the plain committing Enter that follows, and the rollover Shift for the next doubled consonant exercise the stablyai#11616 and stablyai#11937 fixes in one session. Each half was covered separately; this fails on main and passes here.
OrcaWin pushed a commit that referenced this pull request Aug 3, 2026
nwparker added a commit that referenced this pull request Aug 3, 2026
Adapted from #11616 commit 9f449d7 and #12120 commit 290f42a.

Co-authored-by: holdn2 <[email protected]>
nwparker added a commit that referenced this pull request Aug 3, 2026
Adapted from #11616 commit 9f449d7 and #12120 commit 290f42a.

Co-authored-by: holdn2 <[email protected]>
@nwparker

nwparker commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #12265, which landed the physical-Enter classification together with the broader Windows IME shortcut guard and regression coverage. Thank you for isolating and validating the original failure mode.

@nwparker nwparker closed this Aug 3, 2026
@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

5 participants