Repository navigation
fix(terminal): require press-time evidence for the Windows IME Enter-keyup newline - #11937
dogfooter8750 wants to merge 2 commits into
Conversation
… Enter-keyup newline On Windows, the Enter-keyup synthesis path inferred the modified-Enter chord from release-time modifier state. A plain committing Enter (Process/229, no modifiers) followed by a rolled-over Shift for the next doubled consonant made the keyup report shiftKey=true and synthesized a Shift+Enter the user never chorded; a directly-sent Shift+Enter could likewise send a second newline from its keyup once the next composition started. Record observed Enter keydowns (code -> timeStamp) and let the keyup synthesis run only for presses whose keydown the IME swallowed entirely; a balancing keyup that copies the keydown timeStamp keeps the evidence for the later physical release. Refs stablyai#11878 Co-Authored-By: Claude Fable 5 <[email protected]>
Greptile SummaryThis PR narrows the Windows IME Enter-keyup synthesis path in
Confidence Score: 5/5The change strictly narrows an existing synthesis path with no new byte-injection surface, guarded behind the existing isWindows check. The evidence map logic is correct across all edge cases: recording, draining, balancing-keyup non-drain, auto-repeat, and cleanup are all properly placed and verified by the new test suite. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/terminal-pane/keyboard-handlers.ts | Adds an evidence map that gates the IME Enter-keyup synthesis branch; recording, draining, and cleanup are all correctly placed and the IME-swallowed-keydown path (no observed keydown) is preserved by construction. |
| src/renderer/src/components/terminal-pane/keyboard-handlers-ime-enter-keyup.test.tsx | New test suite with six cases covering the critical paths: rollover suppression, balancing-keyup non-drain, rapid double-press, auto-repeat, positive-control synthesis, and direct-send non-duplication. |
Sequence Diagram
sequenceDiagram
participant KB as KeyboardEvent
participant OKD as observedEnterKeydownTimeStamps
participant KD as onKeyDown
participant KU as onKeyUp
participant SYN as IME Synthesis
Note over KB,SYN: Normal IME commit (keydown swallowed entirely)
KB->>KD: "keydown key=Process/229, code=Enter, ts=10"
Note over KD: blank-code 229 not recorded
KB->>KU: "keyup key=Enter, code=Enter, ts=30, shiftKey=true"
KU->>OKD: get('Enter') undefined
Note over KU: enterKeydownWasObserved = false
KU->>SYN: synthesize Shift+Enter
Note over KB,SYN: Rollover scenario
KB->>KD: "keydown key=Process/229, code=Enter, ts=10, isComposing"
KD->>OKD: set('Enter', [10])
KB->>KU: "keyup key=Enter, ts=30, shiftKey=true"
KU->>OKD: get('Enter') [10], shift() delete
Note over KU: enterKeydownWasObserved = true BLOCKED
Note over KB,SYN: Balancing keyup (same timeStamp)
KB->>KD: "keydown key=Process/229, code=Enter, ts=10"
KD->>OKD: set('Enter', [10])
KB->>KU: "keyup key=Enter, ts=10 balancing"
Note over KU: includes(10) true do NOT drain, BLOCKED
KB->>KU: "keyup key=Enter, ts=30 physical release"
KU->>OKD: shift() delete
Note over KU: enterKeydownWasObserved = true BLOCKED
Reviews (2): Last reviewed commit: "fix(terminal): keep press evidence per E..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe keyboard handler records qualifying Windows and IME Enter keydowns before early returns. It uses bounded timestamped evidence to distinguish balancing keyups from physical releases and prevents incorrect newline synthesis. The state clears on window blur and effect cleanup. New tests cover modifier rollover, balancing keyups, swallowed Enter keydowns, auto-repeat, rapid presses, and duplicate prevention for directly handled 🚥 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 |
A single slot per code let a rapid second Enter press go unguarded: the first release found a mismatched timeStamp, dropped the only entry, and the second release then synthesized the Shift+Enter this guard exists to prevent. Track one entry per press and drain exactly one per physical release, so every press stays guarded until its own release. Auto-repeat keydowns do not stack an entry, since the whole run ends in one release, and the list is bounded so a press whose release never arrives cannot grow it without end. Refs stablyai#11878 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Good catch on the map-overwrite edge case — it was real, and I reproduced it before fixing it. Driving the harness with two Enter keydowns (ts 10, 20) before either release, then two keyups (ts 30, 40) with a rolled-over Shift, the second keyup synthesized Fixed in e17d22c by tracking one entry per press instead of one slot per code ( Two details worth flagging since they are new surface:
Tests: added |
|
Heads up — I've opened #12120 as a draft that carries your commit One change I should flag: rather than adding Your rollover case turned out to be load-bearing for the combined fix: the regression test This is not meant to supersede your PR — maintainers may well prefer landing it directly, |
|
Nothing misrepresented — the attribution is more careful than it needed to be, and folding the tests into On your offer to close: please don't. A single combined fix is what actually helps the people on #11878, and one branch carrying the keydown predicate, the keyup gate, and the deferred-commit work is a much better thing for a maintainer to review than four PRs landing in some arbitrary order. I'll leave this PR open, but explicitly as a fallback rather than as competition. #12120 is a draft carrying work from four authors, so if it needs time in review, this one is two files with green checks and is cheap to take on its own for the keyup half. Whichever lands, I'm happy — and if a maintainer signals they want #12120, I'll close this myself so it isn't in the way. One carry-over when you next touch the branch, detail and measurements in my comment there: |
A single slot per code let a rapid second Enter press go unguarded: the first release found a mismatched timeStamp, dropped the only entry, and the second release then synthesized the Shift+Enter this guard exists to prevent. Track one entry per press and drain exactly one per physical release, so every press stays guarded until its own release. Auto-repeat keydowns do not stack an entry, since the whole run ends in one release, and the list is bounded so a press whose release never arrives cannot grow it without end. Adapted from stablyai#11937 commit e17d22c; tests were folded into the existing colocated suite. Refs stablyai#11878
Adapted from stablyai#11937 commit c865c0b; tests were folded into the existing colocated suite.
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.
A single slot per code let a rapid second Enter press go unguarded: the first release found a mismatched timeStamp, dropped the only entry, and the second release then synthesized the Shift+Enter this guard exists to prevent. Track one entry per press and drain exactly one per physical release, so every press stays guarded until its own release. Auto-repeat keydowns do not stack an entry, since the whole run ends in one release, and the list is bounded so a press whose release never arrives cannot grow it without end. Adapted from stablyai#11937 commit e17d22c; tests were folded into the existing colocated suite. Refs stablyai#11878
|
Closing — this landed on
Thanks @holdn2 for carrying it into the combined branch, and in particular for reproducing each case against the handler before taking it rather than trusting my description — both the rapid-double-press hole and the corrected re-render mechanism surfaced because you did that. And thanks to the maintainers for the wider fix; the keyup half was only one of several paths that needed closing. I have since root-caused the re-render amplifier I flagged, and opened it separately rather than leave it as an unexplained aside. Summary is in my comment on #12120. |
Summary
Fixes a residual "spontaneous newline" path of #11878 that survives #11616: on Windows, the IME Enter-keyup synthesis branch (
keyboard-handlers.tsonKeyUp) infers the Shift/Ctrl+Enter chord from release-time modifier state. Two user-visible consequences with a Korean IME:Process/229 with no modifiers) followed by a rolled-over Shift for the next doubled consonant (fast typing of 했다 / 아빠 / 얘기 patterns) makes the Enter keyup reportshiftKey=true, and the branch synthesizes a Shift+Enter newline (\x1b\r) the user never chorded. Because the deferred sender fires it on session end or its 200 ms fallback, the newline appears decoupled from any keystroke — exactly the "random newline during lag" reports on [Bug]: Korean double consonants (쌍자음) trigger automatic line breaks in the Windows integrated terminal #11878.The fix records observed Enter keydowns (
code → timeStamp) and lets the keyup synthesis run only for presses whose keydown the IME swallowed entirely — the case that branch exists for. A balancing keyup that copies the keydown's nativetimeStampkeeps the evidence armed for the later physical release (mirroringreleaseRedispatchedEnter's same-timeStampsemantics). Blank-codeProcess/229 keydowns are deliberately not recorded, so #11616's "blank code falls back to the Enter keyup path" design is preserved.Interplay with #11616 (verified locally): #11616 applies cleanly on top of this branch and the combined tree passes all four IME suites, 66/66.
Screenshots
No visual change.
Testing
keyboard-handlers-ime-enter-keyup.test.tsx— rollover suppression, balancing-keyup retention, keyup-only synthesis preserved (positive control), and no double-send after a direct send. The two suppression tests fail against the pre-fix handler (sendInputreceives"�\r") and pass with it.viteston the affected IME suites: 54/54 on this branch; 66/66 with [P1] fix(terminal): require a physical Enter for Windows IME process-enter #11616 applied on top (keyboard-handlers-ime-enter-keyup,keyboard-handlers-ime,terminal-ime-deferred-newline,terminal-ime-composition-route)oxlint(default andconfig/oxlint-react-doctor.json) andoxfmt --checkon the changed filestsc --noEmit -p config/tsconfig.tc.web.json(the change is renderer-only)pnpm test/pnpm buildwere not run in this environment (native runtime build unavailable); the change surface is two renderer TS filesAI Review Report
Three independent review passes (adversarial correctness, cross-platform, security/perf) all approved; two of their findings were folded back into the change:
releaseRedispatchedEnterhousekeeping still runs on the suppressed path, and per-codekeying keeps Enter and NumpadEnter evidence independent. Review-driven changes: (1) evidence is recorded ahead of everyonKeyDownearly return, so keydowns on editable/out-of-scope targets also disqualify their keyup; (2) the originalSetwas replaced with acode → timeStampmap so a balancing keyup (timeStamp copied from the keydown) does not consume the evidence before the physical release.isWindows; macOS/Linux behavior is byte-identical. Remote/SSH panes are unaffected — the change only suppresses sends ahead of the unchanged transport abstraction.code229 keydowns by construction, so [P1] fix(terminal): require a physical Enter for Windows IME process-enter #11616's blank-code keyup fallback still synthesizes. Verified empirically (66/66 with [P1] fix(terminal): require a physical Enter for Windows IME process-enter #11616 overlaid).key === 'Enter', a stale entry can suppress at most one future keyup-only synthesis for that code; it self-heals on the next keyup and is cleared on window blur and effect cleanup.Security Audit
\x1b\rreaches the PTY; no new byte-injection path is added.Enter/NumpadEnteronly) and cleared on keyup consumption, window blur, and effect cleanup.Notes
isWindows-only.sendTerminalInputAfterComposition's 200 ms fallback fires without re-checking pending composition, so even a legitimate deferred newline can land mid-composition under renderer lag. Detailed in a comment on [Bug]: Korean double consonants (쌍자음) trigger automatic line breaks in the Windows integrated terminal #11878.🤖 Generated with Claude Code