Repository navigation
fix(terminal): send a committed IME string without waiting for the next composition - #12043
kunsanglee wants to merge 2 commits into
Conversation
…xt composition A committed composition reached the pty one session late whenever the commit had not propagated as an input event and the next compositionstart arrived in the same task. The shell then had nothing to echo, the cursor never advanced, and the overlay for the string being composed painted over the previous cell. Korean meets both conditions at every syllable boundary, because one jamo key commits the previous syllable and opens the next one, so a continuous run is unreadable. Pinyin, kana-kanji and Telex reproduce identically whenever their event sequence takes that shape. CompositionHelper.compositionstart cancelled the pending composition's finalizer before closing its session, and _endPendingCompositionSession sends nothing to the pty. Nothing else was scheduled, so the text waited for the next composition's _finalizeComposition to flush it on its way past. Leave the finalizer armed. It runs after compositionstart records nextCompositionStart, so the boundary is known and the string leaves one task later instead of one composition later. Sending inside compositionstart was tried first and breaks the IBus final-consonant transfer, where the textarea has not settled yet. The source maps are realigned for the 55 removed characters, not just their sourcesContent, by the script this commit adds: segments past the deletion move back, segments that named the removed statement are dropped, and no other generated line changes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HL8CxXZYghUKJEQpYhKeGg
835cc7c to
ff486fd
Compare
|
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)
📝 WalkthroughWalkthroughThe pull request adds a CLI script that adjusts source-map mappings after deleting text from a generated bundle. It locates the deletion with a unique marker, updates affected mappings, preserves unaffected lines, and validates the result before writing the map. It also adds happy-dom/Vitest regression tests for continuous macOS Hangul IME composition in xterm, including consecutive syllable commits and deferred input handling. 🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ffdc7662-afbd-41e1-9ac1-cb397e90c1b4
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
config/patches/@[email protected]config/scripts/shift-sourcemap-after-bundle-edit.mjssrc/renderer/src/components/terminal-pane/terminal-ime-xterm-continuous-hangul-run.test.ts
Greptile SummaryThis PR fixes a timing bug in the vendored
Confidence Score: 5/5Safe to merge. The change is a one-call removal in a well-tested vendored module, the deferred timer path it re-enables has been in xterm before, and the existing guard on the timer body prevents double-emission. The fix is minimal and its invariant is airtight: the timer checks Files Needing Attention: No files require special attention. The patch to the minified bundles was already verified against the TypeScript source, the sourcemap delta was measured and validated, and the new test cases are independent and deterministic.
|
| Filename | Overview |
|---|---|
| config/patches/@[email protected] | Drops _cancelPendingFinalizer from compositionstart and sets nextCompositionStart so the armed timer correctly slices the committed syllable; both lib/xterm.js and lib/xterm.mjs patched with matching sourcemap updates. |
| config/scripts/shift-sourcemap-after-bundle-edit.mjs | New dev-time utility that decodes VLQ source-map segments, drops those inside a deletion range, shifts the rest back, validates no other generated line changes, and refuses to write if any mapped column would overrun the line length. |
| src/renderer/src/components/terminal-pane/terminal-ime-xterm-continuous-hangul-run.test.ts | Two focused integration tests using the xterm Terminal directly; per-syllable emission assertions and a nextCompositionStart-bound proof that together fail without the fix and pass with it. |
| pnpm-lock.yaml | Patch SHA-256 hash updated to reflect the new patch content; no other dependency changes. |
Sequence Diagram
sequenceDiagram
participant KB as Keyboard / IME
participant CH as CompositionHelper
participant PT as pty (onData)
note over KB,PT: Korean syllable boundary — compositionstart in the same task as compositionend
KB->>CH: compositionend("그")
CH->>CH: "_finalizeComposition(true)<br/>creates pending1, arms finalizerTimer"
note right of CH: OLD CODE: compositionstart<br/>calls _cancelPendingFinalizer(pending1)<br/>timer silently dropped → 그 is never sent
KB->>CH: compositionstart (리 begins)
note right of CH: NEW CODE: timer stays armed<br/>sets pending1.nextCompositionStart = cursor(1)
note over CH: --- next macrotask ---
CH->>CH: "finalizerTimer fires<br/>_getPendingTextareaInput(pending1)<br/>= value[0..nextCompositionStart=1] = "그""
CH->>PT: triggerDataEvent("그") ✓
KB->>CH: compositionend("리")
CH->>CH: "_finalizeComposition(true)<br/>creates pending2, arms finalizerTimer"
KB->>CH: compositionstart (고 begins)
note right of CH: timer stays armed<br/>sets pending2.nextCompositionStart = cursor(2)
note over CH: --- next macrotask ---
CH->>CH: finalizerTimer fires → "리"
CH->>PT: triggerDataEvent("리") ✓
KB->>CH: compositionend("고")
CH->>CH: "_finalizeComposition(true)<br/>no new compositionstart — ordinary path"
note over CH: --- next macrotask ---
CH->>PT: triggerDataEvent("고") ✓
Reviews (2): Last reviewed commit: "fix(terminal): harden the source-map shi..." | Re-trigger Greptile
Review feedback on the PR: - reject a deletion containing a line terminator, since the shift only realigns one generated line and later lines would move unadjusted - fail with the intended message rather than a TypeError when a generated line has no segment left to carry running state, which also keeps Math.max off an empty spread - dispose terminals from afterEach so a throwing assertion cannot leak one Verified the script still reproduces the committed patch byte for byte. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HL8CxXZYghUKJEQpYhKeGg
|
Addressed the review feedback in
Re-verified after the change that the script still reproduces the committed patch byte for byte: reset to the parent commit's patch, reinstalled, re-ran the bundle edit, the shift and the comment substitution, and all five post-image blob hashes match. |
|
Superseded by #12278 and #12280. The finalizer mechanism identified here was landed with reproducibly rebuilt xterm artifacts, and #12280 then verified physical macOS 2-Set input end to end. Thank you @kunsanglee for independently isolating the one-session-late commit and the IBus constraint. |
Summary
A committed IME composition reaches the pty one session late whenever the commit did not propagate as an
inputevent and the nextcompositionstartarrives in the same task. The shell then has nothing to echo, the cursor never advances, and the overlay for the string being composed paints over the cell the previous one should own.Korean makes this constant. One jamo key commits the previous syllable and opens the next, so every syllable boundary meets both conditions and a continuous run is unreadable —
그리고shows as그고. The bytes are fine; pressing Enter sends그리고intact. Measured against the real patchedCompositionHelper:A devtools trace of
.composition-viewconfirms the cursor never moves:leftstays at17pxfor the whole word.This is not Korean-specific. There is no language or character-range branch in
compositionstart,_finalizeComposition,_sendPendingComposition,_endPendingCompositionSessionor_getPendingTextareaInput. Replaying the same event shape with pinyin (你好/世界), kana-kanji (日本/語) and Vietnamese Telex (tiến/Việt) reproduces it identically, and this change corrects all of them. Those IMEs commit on a dedicated key and open the next composition on the following keypress, so they usually land one task apart and escape it; Korean cannot.Cause
CompositionHelper.compositionstartcancelled the pending composition's finalizer before closing its session:_endPendingCompositionSessiononly dispatches a session-end carryingdataPendingReconciliation: true; it sends nothing to the pty. With the finalizer cancelled nothing else was scheduled, so the committed text sat there until the next composition's_finalizeCompositionflushed it on its way past.Any non-composition key in between hides the bug —
CompositionHelper.keydowncalls_finalizeComposition(false)and flushes first. So does a commit that propagates asinsertText.Fix
Drop the
_cancelPendingFinalizercall and leave the timer armed.compositionstartassignspending.nextCompositionStarta few lines further down, so by the time the timer runs the exact boundary between the committed text and the new composition is known and_getPendingTextareaInputreturns the right slice. The string leaves one macrotask aftercompositionstartinstead of one composition later.This restores the timing xterm had before the pending-composition machinery landed: the original code committed on a
setTimeout(…, 0)for the reason its comment still gives, that composition events fire before the textarea settles. What changed is only that the wait is bounded again.Sending directly inside
compositionstartwas tried first and breaks IBus. Inpreserves a Korean final-consonant transfer across compositionsthe textarea still reads앙when the nextcompositionstartfires; the transfer to아+ㅇonly shows up on the followingcompositionupdate. That path emitted앙아instead of아아. The reconciliation window is whatdataPendingReconciliationis named for, so this shortens the wait to one task rather than removing it.Source maps
The patch edits shipped minified bundles, so
mappingshas to move with them.config/scripts/shift-sourcemap-after-bundle-edit.mjsdoes it and is included here, because otherwise the next@xterm/xtermbump has to redo the surgery by hand with nothing to check it against.For the 55 characters removed from one generated line in each bundle: segments past the deletion move back by 55, segments that named the removed statement are dropped because their code is gone, and no other generated line changes — asserted by the script, which refuses to write if the running source-position state at the end of the line would shift.
Verified with
@jridgewell/trace-mapping: the deletion column now resolves toCompositionHelper.ts:146:6, the statement that took its place. Leavingmappingsuntouched would have overrun the generated line by 44 and 52 columns and mis-attributed roughly 85% of each bundle.Rebuilding instead of patching is not available: the published tarball omits
bin/,webpack.config.jsandtsconfig.json, and a rebuilt bundle would differ everywhere the minifier picked other identifiers.Screenshots
No visual change in the sense of new UI. The user-visible effect is that the terminal composition overlay stops painting over the previous cell during a continuous IME run; there is no new or changed component to screenshot.
Testing
pnpm lintpnpm typecheckpnpm test— 4056 files / 43163 pass; 3 pre-existing failures, see belowpnpm buildThe 3 failures are environmental, not from this PR.
config/scripts/check-root-directory-entries.test.mjsshells out to.github/scripts/check-root-directory-entries.sh, which usesdeclare -A. macOS ships bash 3.2, where that isdeclare: -A: invalid option, so the guard exits 2 against its own throwaway fixture repo before reading anything. It never looks at this branch. CI runs it on bash 5.New tests in
terminal-ime-xterm-continuous-hangul-run.test.ts, using the harness from the existing de-duplication suite. Both fail without the change:expected [] to deeply equal [ '그' ]nextCompositionStartbound the fix relies on; deleting that bound yields[ '그ㄹ' ]instead of[ '그' ]and nothing else in the suite notices.The reproduction hinges on not firing an
insertTextinput event aftercompositionend; the real Chromium trace has none, and adding one routes through the healthy path and hides the bug.Also confirmed:
config/scripts/package-electron-runtime-contract.test.mjspasses (22), and a freshpnpm install --frozen-lockfilein an isolated tree reproduces the declared post-image hashes.AI Review Report
Two rounds of independent reviews, run in parallel and unaware of each other, on simplicity, impact radius, adversarial refutation, patch hygiene, source-map correctness, test coverage, and language generality.
What they flagged and what changed as a result:
sourcesContenthad been updated;mappingsstill described the pre-deletion bundle. A full-column sweep with@jridgewell/trace-mappingmeasured the overrun. Fixed by shifting the affected generated line, and the transform script is now in the tree.nextCompositionStartbound had no coverage at all. Deleting that line left all 79 IME tests green. Added the case above.if (this._pendingComposition)branches incompositionstart. It would change thedatapayload of thedataPendingReconciliationevent, which no consumer reads, and widen the divergence from upstream for no behavioural gain.Adversarial round: 500 differential fuzz runs with macrotask boundaries injected between events at 25%, across macOS, IBus and late-commit shapes plus ASCII/Enter/Escape, checking total equality, prefix-monotonicity of intermediate output, and no-regression against the old bundle. Zero violations; 230/500 runs emitted earlier than before. Fifteen hand-written scenarios and six boundary probes matched the old bundle exactly.
Cross-platform. Reviewed explicitly for macOS, Linux and Windows. The change is inside vendored renderer code with no platform branch, no shortcut, label, path or shell behaviour, and no Electron main-process surface. Per platform: macOS Hangul is the reported reproduction; Linux IBus is covered by the recorded traces in
tests/e2e/terminal-ime-observed-event-sequences.ts, replayed before and after with identical output (한abc글\r,테a스\r); WindowsProcess/229 handling is unaffected becauseCompositionHelper.keydowngates on_isComposing || hasPendingCompositionFinalizationand_isComposingstays true through the composition. SSH and remote runtimes see the sameonDatachunks (["그","리","고"]) with only the arrival time changing, soremote-runtime-pty-batchingordering is untouched.Security Audit
No new input handling, command execution, path handling, auth, secrets or IPC surface. No Orca source changed.
The dependency angle is the one to look at, since this edits a vendored patch of
@xterm/xterm. Reviewed and verified:indexblob hashes in the patch match the produced files. pnpm does not verify them — it parses them but never hashes content — so they were checked by hand rather than relied on.pnpm-lock.yamlcarries only the patch-hash propagation, which is the sha256 of the patch file; the old hash appears nowhere in the repo, includingmobile/pnpm-lock.yaml. CI runspnpm install --frozen-lockfile, so a patch edited without the lockfile would fail there.Terminal input reaching the pty earlier does not change what is sent, only when. The full run emits the identical byte sequence.
Notes
Known window. If an IME rewrites already-committed text more than one task after
compositionend, the old text is already out and cannot be retracted; constructed synthetically that yields글리where the previous behaviour yielded그리. No IME sequence recorded in this repo has that shape: the IBus rewrite completes in the same task ascompositionend, and the macOS Hangul final-consonant transfer completes inside the composition. Waiting for the nextcompositionupdateinstead of one task would close the window, but it puts the flush back on the user's next keystroke, so the shell has no time to echo and the overlap returns on the first jamo of each syllable.Unmeasured. How often real Sogou, Kotoeri or Unikey binaries produce the triggering event shape. The repo has no recorded traces for them, and the mechanism was confirmed by replay rather than on hardware.
Follow-up worth considering. A check next to
config/scripts/package-electron-runtime-contract.test.mjsasserting that every patched bundle's maximum mapped column stays inside its generated line would have caught the source-map defect above in CI.tests/e2e/terminal-ime-observed-event-sequences.tscurrently records IBus only; a macOS capture would give the shape this fix targets a recorded counterpart.