Repository navigation
Conversation
📝 WalkthroughWalkthroughThe change updates Windows IME Enter keyup handling to avoid synthetic newline input during Shift toggles. It adds deletion-release tracking for native composition Backspace and Delete events, allowing keydowns to reach xterm while suppressing paired keyups. Unit, adversarial, and end-to-end tests cover composition editing, native updates, preedit state, terminal output, PTY logging, and Windows IME event simulation. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
Greptile SummaryThis PR fixes two Windows IME edge cases left uncovered by #11293: (1) a one-letter preedit that couldn't be deleted because
Confidence Score: 5/5Safe to merge; the two targeted Windows IME regressions are fixed without disturbing the transaction model from #11293, and each new code path is covered by unit, integration, and E2E tests. Both fixes are narrow and surgical: the deletion guard is a simple one-shot state machine with a 1 s TTL, and the fallback removal affects only the unowned-chord case that had no legitimate callers. The new isTerminalImeProcessEnter narrowing correctly gates on physical code rather than logical key, and the existing Shift+Enter deferred-newline path that relies on modifiedEnterChordOwner.absorb returning true is unaffected. The xterm patch is not reviewable at source level, but the adversarial integration tests exercise all the CompositionHelper paths that matter here. Files Needing Attention: config/patches/@[email protected] — the patch is minified and cannot be code-reviewed directly; the adversarial tests in terminal-ime-xterm-adversarial.test.ts provide the best available confidence in its correctness.
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/terminal-pane/terminal-ime-deletion-release-guard.ts | New one-shot guard that tracks a Windows IME composition deletion keydown and suppresses only its paired ordinary keyup; correct one-shot semantics with 1 s TTL and composition-release pass-through. |
| src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts | Adds isTrackedCompositionDeletion early-return to let deletion keydown-229 reach xterm, and an early suppress for pendingCompositionDeletionReleaseActive; both paths are well-guarded and tested. |
| src/renderer/src/components/terminal-pane/keyboard-handlers.ts | Removes the unowned modified-Enter keyup fallback that could fire on a Shift-toggle orphan Enter; legitimate Shift+Enter still routes through the modifiedEnterChordOwner absorb path that is preserved. |
| src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts | isTerminalImeProcessEnter now requires code==='Enter' |
| src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts | Correctly wires the deletion release guard: consume fires before arm so consecutive deletions arm a fresh guard, and compositionActive is captured once and reused for both arm and imeKeyboardOptions. |
| tests/e2e/chinese-ime-chat-input-repro.spec.ts | Extends the combined E2E test with Shift-toggle and IME Backspace assertions including raw PTY input-count checks; adds a dedicated Shift-toggle regression test with Windows UA policy. |
| tests/e2e/helpers/windows-ime-native-events.ts | New CDP helper module that faithfully replays Chromium's native Microsoft Pinyin Backspace and Shift-toggle event sequences, plus utilities for reading raw PTY input log files. |
| config/patches/@[email protected] | Updated xterm patch (minified JS); exact diff not reviewable at source level, but the adversarial integration tests exercise the relevant CompositionHelper paths. |
Sequence Diagram
sequenceDiagram
participant IME as Windows IME
participant KH as Keyboard Handler
participant Guard as DeletionReleaseGuard
participant Policy as BypassPolicy
participant Xterm as xterm CompositionHelper
Note over IME,Xterm: Windows Pinyin one-letter preedit deletion
IME->>KH: "keydown {key:'Process', code:'Backspace', keyCode:229}"
KH->>Guard: consumeRelease(event) → false (guard empty)
KH->>Guard: "arm(event, compositionActive=true) → guard armed for 'Backspace'"
KH->>Policy: "shouldSuppress? → isTrackedCompositionDeletion=true → false (PASS THROUGH)"
KH->>Xterm: keydown reaches CompositionHelper
Xterm->>Xterm: defer preedit reconciliation (one event-loop turn)
IME->>KH: compositionupdate '' / compositionend
Xterm-->>Xterm: native progress wins — preedit cleared
IME->>KH: "keyup {key:'Process', code:'Backspace', keyCode:229}"
KH->>Guard: "consumeRelease → isCompositionRelease=true → false (guard stays armed)"
KH->>Policy: "shouldSuppress? → keyCode=229, isComposing → true (SUPPRESS)"
IME->>KH: "keyup {key:'Backspace', code:'Backspace', keyCode:8}"
KH->>Guard: "consumeRelease → isPairedRelease=true, guard cleared → true"
KH->>Policy: "pendingCompositionDeletionReleaseActive=true → SUPPRESS"
Note over KH,Xterm: Backspace keyup never reaches PTY
Note over IME,Xterm: Windows Shift-toggle spurious newline (fixed)
IME->>KH: keydown Process/ShiftLeft/229
IME->>KH: keydown Shift/ShiftLeft/16
IME->>KH: keyup Process/ShiftLeft/229
Note over KH: key≠'Enter' → early return, no deferred newline
IME->>KH: "orphan Enter keyup (key:'Enter', shiftKey=true)"
KH->>KH: modifiedEnterChordOwner.absorb → false (no owner)
Note over KH: fallback block REMOVED → falls through to chord release only
Reviews (2): Last reviewed commit: "docs(terminal): document IME release own..." | Re-trigger Greptile
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-ime-deletion-release-guard.ts (1)
12-19: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicated Backspace/Delete key-matching predicate. Both sites independently encode "is this event a tracked IME deletion key" (
key/code∈ {Backspace,Delete}); they currently agree but can silently drift since nothing keeps them in sync.
src/renderer/src/components/terminal-pane/terminal-ime-deletion-release-guard.ts#L12-L19: exportresolveTerminalImeDeletionKey(or a boolean wrapper around it) for reuse.src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts#L125-L135: replace the inlineevent.key === 'Backspace' || ... || event.code === 'Delete'check with the shared predicate from the guard module.♻️ Proposed extraction
--- a/src/renderer/src/components/terminal-pane/terminal-ime-deletion-release-guard.ts +++ b/src/renderer/src/components/terminal-pane/terminal-ime-deletion-release-guard.ts @@ -function resolveTerminalImeDeletionKey( +export function resolveTerminalImeDeletionKey( event: Pick<XtermBypassEvent, 'key' | 'code'> ): TerminalImeDeletionKey | undefined {--- a/src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts +++ b/src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts @@ +import { resolveTerminalImeDeletionKey } from './terminal-ime-deletion-release-guard' @@ const isTrackedCompositionDeletion = event.type === 'keydown' && compositionActive && event.keyCode === 229 && - (event.key === 'Backspace' || - event.key === 'Delete' || - event.code === 'Backspace' || - event.code === 'Delete') + resolveTerminalImeDeletionKey(event) !== undefined
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 71b7f2ae-4a55-448d-a8d9-4023891db0d4
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (13)
config/patches/@[email protected]src/renderer/src/components/terminal-pane/keyboard-handlers-ime.test.tsxsrc/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.tssrc/renderer/src/components/terminal-pane/terminal-ime-deletion-release-guard.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-deletion-release-guard.tssrc/renderer/src/components/terminal-pane/terminal-ime-xterm-adversarial.test.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy-non-mac.test.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.test.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.tstests/e2e/chinese-ime-chat-input-repro.spec.tstests/e2e/helpers/windows-ime-native-events.ts
|
Cross-compared this with the fixes now on main: #12265 supersedes the Shift/Enter portion, and #12273 fixes cancelled stale-preedit replay. The Windows Process/229 Backspace/Delete reconciliation and paired Kitty keyup ownership here remain distinct and are not yet landed, so I am leaving this PR open rather than incorrectly marking that work resolved. A current-main extraction should add an explicit Windows gate, adapt around #12265's capture guard, and cover delayed native progress before reuse. |
|
The native Windows behaviors covered here are now resolved on main: modified Process events require a physical Enter, cancelled preedits no longer replay stale text, and #12276 preserves the Microsoft Pinyin Shift-commit trace with @yoke233 credited as co-author. #12278 also lands the complementary Hangul syllable-flush fix. Thank you @yoke233 for the native traces and regression coverage. |
Summary
Follow-up to #11293, based on native Microsoft Pinyin traces captured in Electron on Windows.
The native events differ from the synthetic model used by the first revision of this PR:
keydown key=Process code=Backspace keyCode=229, followed by an empty composition update/input, thenkeyup Process/229andkeyup Backspace/8.Process code=ShiftLeft keyCode=229plus the ordinary Shift events. It does not emit Enter. The previous predicate checkedkey=Process, modifier state, andkeyCode=229, but notcode, so it could misclassify this Shift-owned Process event as Shift+Enter and submit a newline.This revision:
key=Process/code=Backspace|Deleteshape and the logicalkey=Backspace|Deletecompatibility shape;code=Enter|NumpadEnterbefore treatingProcess/229as a modified Enter, socode=ShiftLeftcannot create a newline;Upstream
mainwas checked before the update and remains the direct base of this PR; no later upstream commit fixes these native Windows event shapes.Screenshots
No visual change.
Testing
pnpm lint(full repository lint not run)pnpm typecheckpnpm test(full repository suite not run)pnpm buildAdditional verification:
s, with no newline.CSI > 10 u) and proves the pairedBackspace/8keyup emits nothing.oxlint, React Doctor lint, andoxfmtthrough the commit hook.XTERM_VERSION = 6.1.0-beta.287; the patch contains no6.0.0marker.AI Review Report
Independent reviews checked implementation quality, state lifetime, generated artifacts, test fidelity, and cross-platform regressions.
They flagged four issues in the earlier revision, all addressed here:
6.0.0; all artifacts were regenerated withsrc/common/Version.tsfrom6.1.0-beta.287.keytocoderegressed events with an unavailable physical code; both shapes are now accepted and tested.Backspace/8keyup could leak under Kitty event-type reporting; a narrow, expiring paired-release guard and Kitty-mode regression test were added.Cross-platform review confirmed the new release guard only arms from
keyCode=229during an active composition. macOS and Linux standalone-229 behavior, Linux/Sogou candidate guards, folder workspaces, SSH transports, shortcut labels, paths, and shell behavior are unchanged.Security Audit
No auth, secrets, IPC contracts, command execution, or production path handling were added. The CDP event dispatch and PTY log parsing live only in E2E helpers and operate on test-created files. The production change is limited to renderer keyboard-event classification and the existing pinned xterm patch; no dependency version changed.
Notes