Repository navigation
Conversation
Backspacing away an entire Pinyin preedit ended the composition with empty data, no textarea residue, and no input/keypress events — yet _sendPendingComposition fell back to the last non-empty compositionupdate data and typed its first character into the PTY. Only trust that fallback when observed input evidence corroborates it; a composition with no evidence in any channel was cancelled. Fixes the macOS Pinyin regression from stablyai#11293 (stray letter left after deleting a preedit); same fix covers IBus/fcitx Backspace cancellation. Co-Authored-By: Claude Fable 5 <[email protected]>
|
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 ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdded a happy-dom Vitest suite for xterm IME composition behavior. The suite provides terminal and event helpers, mocks canvas measurement, and cleans up terminals and DOM state. Tests cover Pinyin preedit deletion followed by cancellation, cancellation without textarea input events, and an empty composition end followed by 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ 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 a bug where cancelling an IME composition by backspacing away the entire preedit (e.g. macOS Simplified Chinese Pinyin) would cause the stale last
Confidence Score: 4/5Safe to merge; the change is narrow and well-tested, touching only IME composition cancellation logic with no impact on normal commits or unrelated input paths. The one-line semantic change in Files Needing Attention: The
|
| Filename | Overview |
|---|---|
| config/patches/@[email protected] | Core fix applied here: _sendPendingComposition now gates the compositionData fallback behind observedInput, preventing stale preedit from being emitted on cancel. Minor inconsistency: _endPendingCompositionSession retains the unguarded compositionData fallback for its provisional session-end event. |
| src/renderer/src/components/terminal-pane/terminal-ime-xterm-composition-cancel.test.ts | New test file covering the exact Pinyin backspace regression, a no-input-events cancel variant, and a regression guard for the IBus Hangul commit pattern. |
| pnpm-lock.yaml | Lockfile updated as a side-effect of pnpm patch-commit normalising patch metadata; no dependency version changes. |
Sequence Diagram
sequenceDiagram
participant IME as IME (Chromium)
participant CH as CompositionHelper
participant PTY as PTY
Note over IME,PTY: Backspace-cancel path (this fix)
IME->>CH: compositionstart()
IME->>CH: compositionupdate('c'), compositionupdate('ce'), ...
Note over CH: _lastCompositionData = 'c'
IME->>CH: compositionupdate('') + textarea empty + deleteContentBackward
IME->>CH: compositionend('')
CH->>CH: _finalizeComposition(true, '') creates pending
Note over CH: finalizerTimer fires
CH->>CH: _sendPendingComposition - observedInput is empty
Note over CH: yields '' (FIXED - was 'c' before)
CH-->>PTY: nothing emitted
Note over IME,PTY: Normal commit path (unaffected)
IME->>CH: compositionstart()
IME->>CH: compositionupdate('测试')
IME->>CH: compositionend('测试')
CH->>CH: _finalizeComposition(true, '测试') creates pending
Note over CH: finalizerTimer fires
CH->>CH: "_sendPendingComposition - endData='测试'"
CH->>PTY: triggerDataEvent('测试')
Comments Outside Diff (1)
-
config/patches/@[email protected], line 760-780 (link)Inconsistent
compositionDatafallback in_endPendingCompositionSession_endPendingCompositionSessionstill uses the unguardedpending.compositionDatafallback without theobservedInputguard introduced in_sendPendingComposition. This method fires thexterm-composition-session-endevent withdataPendingReconciliation: truewhen a new composition starts while the previous one is still pending — a scenario that can occur immediately after a backspace-cancel. In that case the event'sdetail.datawill contain the stale preedit ('c') rather than'', inconsistent with the no-emission outcome the fix produces for PTY output. ThedataPendingReconciliation: trueflag tells listeners to treat the value as provisional, so no incorrect characters reach the PTY, but external consumers displaying a commit preview based on this event could briefly show stale text.
Reviews (1): Last reviewed commit: "fix(terminal): stop cancelled IME compos..." | Re-trigger Greptile
|
Landed via #12273 with the original commit authorship preserved. Thank you for the focused root-cause analysis, regression test, and fix. |
Fixes #11936.
Root cause
Backspacing away an entire preedit (e.g. macOS Simplified Chinese Pinyin: type
ceshi, press Backspace 5 times) ends the composition with emptycompositionenddata, an empty textarea, and noinput/keypressevents._sendPendingComposition(added in #11293) then falls back to the last non-emptycompositionupdatedata — the stale preedit remnantc— and emits it to the PTY as if it were committed text. Committing normally is unaffected becausecompositionendcarries the candidate, so the fallback chain never reaches the stale value.Fix
One-line semantic change in the patched
CompositionHelper._sendPendingComposition: only fall back topending.compositionDatawhen observed input evidence (input/keypressdata) corroborates that the composition actually committed. A composition that ends with no evidence in any channel — textarea, end data, input, keypress — was cancelled, and nothing is emitted. Applied tolib/xterm.js,lib/xterm.mjs, and the referencesrc/browser/input/CompositionHelper.tsin the existing@xterm/xtermpatch; the patch file was regenerated bypnpm patch-commit, which also normalized some formatting-only hunks (hence the net line-count drop).The same cancellation shape exists on Linux IBus/fcitx (Backspace over the whole preedit fires
compositionendwith empty data after adeleteContentBackward), so this covers that path too.Tests
New
terminal-ime-xterm-composition-cancel.test.tsdrives the real patched xterm build (same harness style asterminal-ime-xterm-composition-deduplication.test.ts):expected [ 'c' ] to deeply equal []without the fix, reproducing the report exactly;insertText(IBus Hangul shape) still emits, guarding against an over-broad fix.All four existing IME suites pass (72/72):
terminal-ime-xterm-composition-deduplication,terminal-ime-xterm-transaction-events,keyboard-handlers-ime, plus the new file. Manually verified on macOS 26.2 with the built-in Pinyin IME: Backspace over the preedit leaves the shell line clean, and candidate commits are unchanged.🤖 Generated with Claude Code