fix(extension): defer composing reset to stop CJK IME double-send

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
0xteng 2026-05-24 17:16:58 +07:00
parent 920a13a17f
commit e1687ab0d0
1 changed files with 6 additions and 1 deletions

View File

@ -442,10 +442,15 @@
if (ta) {
ta.addEventListener('compositionstart', () => { composing = true; });
ta.addEventListener('compositionend', (e) => {
composing = false;
if (e.data && ws && ws.readyState === WebSocket.OPEN) {
ws.send(new TextEncoder().encode(e.data));
}
// Reset on the next tick. Browsers fire the trailing `input` event
// (→ term.onData) immediately AFTER compositionend, for the same
// composed string. Clearing `composing` synchronously lets that
// event through, double-sending CJK input (e.g. "在在这里这里").
// Deferring keeps onData suppressed for that trailing event.
setTimeout(() => { composing = false; }, 0);
});
}