From d03416467d35c18c510a3b1853d875ecf0b3a57a Mon Sep 17 00:00:00 2001 From: Shuhei Takahashi Date: Fri, 7 Nov 2025 12:26:15 +0900 Subject: [PATCH] Fix key duplication on Android with physical keyboards When typing rapidly on Android with physical keyboards, characters often duplicate on the terminal. This is because physical keyboard events always go through IME on Android, even for plain English characters, and rapid typing causes a race condition in the composition helper. This patch fixes the issue by making sure textarea changes are handled correctly. --- src/browser/input/CompositionHelper.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/browser/input/CompositionHelper.ts b/src/browser/input/CompositionHelper.ts index b87ebbea07..b4b03a8424 100644 --- a/src/browser/input/CompositionHelper.ts +++ b/src/browser/input/CompositionHelper.ts @@ -41,6 +41,11 @@ export class CompositionHelper { */ private _dataAlreadySent: string; + /** + * The pending textarea change timer, if any. + */ + private _textareaChangeTimer?: number; + constructor( private readonly _textarea: HTMLTextAreaElement, private readonly _compositionView: HTMLElement, @@ -184,8 +189,12 @@ export class CompositionHelper { * IME is active. */ private _handleAnyTextareaChanges(): void { + if (this._textareaChangeTimer) { + return; + } const oldValue = this._textarea.value; - setTimeout(() => { + this._textareaChangeTimer = window.setTimeout(() => { + this._textareaChangeTimer = undefined; // Ignore if a composition has started since the timeout if (!this._isComposing) { const newValue = this._textarea.value;