From 669afa15697b407291a0cd03b0cb1ac5fd25726c Mon Sep 17 00:00:00 2001 From: blueyang Date: Sat, 23 May 2026 20:41:25 +0800 Subject: [PATCH] fix(@wterm/dom): don't leak first IME composition key to PTY When IME composition starts, compositionstart fires AFTER the keydown that triggered it. Without checking isComposing / keyCode 229 / key === "Process", the first key (e.g. 'r' of pinyin) leaks into the PTY before compositionend delivers the committed text. Guard handleKeyDown with the three standard IME signals. --- packages/@wterm/dom/src/input.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/@wterm/dom/src/input.ts b/packages/@wterm/dom/src/input.ts index 5e2bfce..9df955d 100644 --- a/packages/@wterm/dom/src/input.ts +++ b/packages/@wterm/dom/src/input.ts @@ -140,6 +140,16 @@ export class InputHandler { private handleKeyDown(e: KeyboardEvent): void { if (this.composing) return; + // Skip the keydown that fires while an IME is starting (or in the middle + // of) a composition. Without this the first key of a composition leaks + // into the PTY before `compositionstart` flips `this.composing`. + if ( + e.isComposing || + e.keyCode === 229 || + e.key === "Process" + ) + return; + if ((e.metaKey || e.ctrlKey) && e.key === "c") { const sel = window.getSelection(); if (sel && sel.toString().length > 0) return;