Commit 34aad10
committed
fix: serialize IME composition with subsequent keystrokes (#3164)
xterm.js v6.x defers compositionend's final text via setTimeout(0). On fast IME input — an issue that can affect any CJK IME — a next-keydown can reach the PTY before the deferred IME text, producing reordered output.
Two-pronged fix:
1. term-model.ts: drop keydown events while event.isComposing or keyCode === 229, so xterm doesn't forward the composition trigger key to the PTY during composition.
2. termwrap.ts: on compositionend, immediately send e.data via sendDataHandler and queue it in pendingImeDedup. handleTermData drops the matching string when xterm's deferred setTimeout(0) onData fires it again. As a best-effort additional guard, reset xterm's internal _isSendingComposition flag so the deferred callback becomes a no-op when the field name isn't minified. The dedup queue (string[]) supports overlapping composition cycles for very fast input.
History:
This is the same class of bug fixed in #2938, but the patches added there were intentionally removed in #3095 ("upgrade xterm.js to v6.0.0") under the assumption that xterm v6 would handle composition correctly. v6.0.0's CompositionHelper still defers final-text onData via setTimeout(0), so the race resurfaced and was reported as #3164 against v0.14.4. This PR re-fixes it in a way compatible with the v6 codebase, using a dedup queue rather than the v5-era patches.
Closes #31641 parent efd450f commit 34aad10
2 files changed
Lines changed: 31 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
700 | 703 | | |
701 | 704 | | |
702 | 705 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
383 | 385 | | |
384 | 386 | | |
385 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
386 | 409 | | |
387 | 410 | | |
388 | 411 | | |
| |||
464 | 487 | | |
465 | 488 | | |
466 | 489 | | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
467 | 495 | | |
468 | 496 | | |
469 | 497 | | |
470 | | - | |
471 | 498 | | |
472 | 499 | | |
473 | 500 | | |
| |||
0 commit comments