From 9e1b89651ade95bd5b5308741591705ca4fcc750 Mon Sep 17 00:00:00 2001 From: sergiochan Date: Tue, 10 Mar 2026 19:36:17 -0700 Subject: [PATCH 1/2] fix(ime): resync textarea position on composition start --- src/browser/CoreBrowserTerminal.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/browser/CoreBrowserTerminal.ts b/src/browser/CoreBrowserTerminal.ts index 828013e9e..057b7837a 100644 --- a/src/browser/CoreBrowserTerminal.ts +++ b/src/browser/CoreBrowserTerminal.ts @@ -414,7 +414,14 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal { this._register(addDisposableListener(this.textarea!, 'keyup', (ev: KeyboardEvent) => this._keyUp(ev), true)); this._register(addDisposableListener(this.textarea!, 'keydown', (ev: KeyboardEvent) => this._keyDown(ev), true)); this._register(addDisposableListener(this.textarea!, 'keypress', (ev: KeyboardEvent) => this._keyPress(ev), true)); - this._register(addDisposableListener(this.textarea!, 'compositionstart', () => this._compositionHelper!.compositionstart())); + this._register(addDisposableListener(this.textarea!, 'compositionstart', () => { + // Ensure the textarea is synced to the latest cursor location before composition begins. + // Some prompt UIs briefly draw helper text and then restore the cursor without triggering a + // new key event, which can leave IME anchoring stale until the first render tick. + this._syncTextArea(); + this._compositionHelper!.compositionstart(); + this._compositionHelper!.updateCompositionElements(); + })); this._register(addDisposableListener(this.textarea!, 'compositionupdate', (e: CompositionEvent) => this._compositionHelper!.compositionupdate(e))); this._register(addDisposableListener(this.textarea!, 'compositionend', () => this._compositionHelper!.compositionend())); this._register(addDisposableListener(this.textarea!, 'input', (ev: InputEvent) => this._inputEvent(ev), true)); From 409f049f39beabd05f2756b3e5c5728aad6e1f53 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 11 Mar 2026 12:02:02 +0900 Subject: [PATCH 2/2] Update src/browser/CoreBrowserTerminal.ts --- src/browser/CoreBrowserTerminal.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/browser/CoreBrowserTerminal.ts b/src/browser/CoreBrowserTerminal.ts index 057b7837a..cedf889b4 100644 --- a/src/browser/CoreBrowserTerminal.ts +++ b/src/browser/CoreBrowserTerminal.ts @@ -415,9 +415,11 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal { this._register(addDisposableListener(this.textarea!, 'keydown', (ev: KeyboardEvent) => this._keyDown(ev), true)); this._register(addDisposableListener(this.textarea!, 'keypress', (ev: KeyboardEvent) => this._keyPress(ev), true)); this._register(addDisposableListener(this.textarea!, 'compositionstart', () => { - // Ensure the textarea is synced to the latest cursor location before composition begins. - // Some prompt UIs briefly draw helper text and then restore the cursor without triggering a - // new key event, which can leave IME anchoring stale until the first render tick. + // Ensure the textarea is synced to the latest cursor location before composition begins. This + // is to workaround a problem where highly dynamic TUIs like agentic CLIs reprint agressively + // would cause the IME to appear in the wrong position. The theory is that when the IME is + // triggered during a partial render the textarea position becomes locked and will not move + // until it is hidden and a custom move occurs. this._syncTextArea(); this._compositionHelper!.compositionstart(); this._compositionHelper!.updateCompositionElements();