Repository navigation
fix(terminal): stop cancelled IME compositions replaying stale preedit - #12273
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 #11293 (stray letter left after deleting a preedit); same fix covers IBus/fcitx Backspace cancellation. Co-Authored-By: Claude Fable 5 <[email protected]>
📝 WalkthroughWalkthroughAdded a happy-dom Vitest suite for xterm IME composition behavior. The suite provides terminal setup, IME event helpers, canvas mocking, cleanup, and event-loop synchronization. It tests full Pinyin preedit deletion, cancellation without input events, and empty composition completion followed by committed 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e05932ae-6adc-4b6f-a19e-304bed5c29d3
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
config/patches/@[email protected]src/renderer/src/components/terminal-pane/terminal-ime-xterm-composition-cancel.test.ts
| afterEach(() => { | ||
| vi.restoreAllMocks() | ||
| document.body.replaceChildren() | ||
| }) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Dispose every opened terminal in afterEach.
If a helper or assertion throws before Line 96, Line 114, or Line 133, terminal.dispose() does not run. document.body.replaceChildren() removes the container but does not dispose the xterm instance. Track opened terminals and dispose them before restoring mocks and clearing the DOM.
Proposed fix
+const openedTerminals = new Set<Terminal>()
+
function openTerminal(): {
emitted: string[]
terminal: Terminal
@@
document.body.appendChild(container)
const terminal = new Terminal()
+ openedTerminals.add(terminal)
terminal.open(container)
@@
afterEach(() => {
+ for (const terminal of openedTerminals) {
+ terminal.dispose()
+ }
+ openedTerminals.clear()
vi.restoreAllMocks()
document.body.replaceChildren()
})
@@
- terminal.dispose()
@@
- terminal.dispose()
@@
- terminal.dispose()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| afterEach(() => { | |
| vi.restoreAllMocks() | |
| document.body.replaceChildren() | |
| }) | |
| const openedTerminals = new Set<Terminal>() | |
| function openTerminal(): { | |
| emitted: string[] | |
| terminal: Terminal | |
| // existing return type members | |
| } { | |
| // existing setup | |
| document.body.appendChild(container) | |
| const terminal = new Terminal() | |
| openedTerminals.add(terminal) | |
| terminal.open(container) | |
| // existing implementation | |
| } | |
| afterEach(() => { | |
| for (const terminal of openedTerminals) { | |
| terminal.dispose() | |
| } | |
| openedTerminals.clear() | |
| vi.restoreAllMocks() | |
| document.body.replaceChildren() | |
| }) |
Summary
compositionend,input, orkeypresscommit evidence as cancelled instead of replaying stale preedit text.compositionendcommits that deliver text through a followinginsertTextevent.Fixes #11936.
Regression source
Introduced by #11293, merge commit
fe6f929c6e(fix(terminal): reconcile cross-platform IME composition lifecycle). That commit added the_sendPendingCompositionfallback to the last non-emptycompositionupdatevalue. It is present inv1.4.163and absent from thev1.4.162-rc.0baseline.A full revert of #11293 would restore the duplicate/drop and composition-ordering bugs it fixed. This PR changes only the ambiguous empty-evidence fallback.
Adapted from #11938 by @Him188; the contributor remains the commit author.
Comparison with #11550
#11550 is complementary rather than an alternative to this fix:
_sendPendingComposition's stalecompositionDatafallback unconditional, so its Windows deletion token does not fix the macOS path in [Bug]: macOS Pinyin IME — first keystroke leaks into the terminal; Backspace over preedit leaves a stray letter (regression since #11293) #11936.Process/229Backspace/Delete: allow the deletion keydown into xterm, reconcile preedit state when native progress is absent, and consume the paired ordinary keyup under Kitty reporting.Enter|NumpadEnterrequirement would regress valid blank/UnidentifiedIME Enter events.The deletion-only portion of #11550 remains a good candidate for a separate follow-up adapted to #12265's current window-capture ownership. Folding it here would mix a Windows keyboard-routing change into the macOS cancellation fix and make both harder to validate.
Before reuse, that extraction also needs an explicit Windows runtime gate and coverage for delayed native progress and complex preedit deletion. #11550 currently lets any platform's composing
keyCode=229Backspace/Delete bypass suppression and reconciles unchanged preedit on the next zero-delay task.Screenshots
No visual change.
Testing
pnpm typecheck:webpnpm lintpasses all changed-code and code-quality stages, then stops atverify:skill-bundle-manifestbecause unrelated generated skill artifacts on currentmainare stale. This PR does not touch those artifacts.Security audit
This only narrows when renderer composition text may be emitted to the PTY. It adds no command execution, IPC, transport, dependency, path, auth, or secret handling changes.