Skip to content

Commit 9e1b896

Browse files
committed
fix(ime): resync textarea position on composition start
1 parent 89980fc commit 9e1b896

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/browser/CoreBrowserTerminal.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,14 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
414414
this._register(addDisposableListener(this.textarea!, 'keyup', (ev: KeyboardEvent) => this._keyUp(ev), true));
415415
this._register(addDisposableListener(this.textarea!, 'keydown', (ev: KeyboardEvent) => this._keyDown(ev), true));
416416
this._register(addDisposableListener(this.textarea!, 'keypress', (ev: KeyboardEvent) => this._keyPress(ev), true));
417-
this._register(addDisposableListener(this.textarea!, 'compositionstart', () => this._compositionHelper!.compositionstart()));
417+
this._register(addDisposableListener(this.textarea!, 'compositionstart', () => {
418+
// Ensure the textarea is synced to the latest cursor location before composition begins.
419+
// Some prompt UIs briefly draw helper text and then restore the cursor without triggering a
420+
// new key event, which can leave IME anchoring stale until the first render tick.
421+
this._syncTextArea();
422+
this._compositionHelper!.compositionstart();
423+
this._compositionHelper!.updateCompositionElements();
424+
}));
418425
this._register(addDisposableListener(this.textarea!, 'compositionupdate', (e: CompositionEvent) => this._compositionHelper!.compositionupdate(e)));
419426
this._register(addDisposableListener(this.textarea!, 'compositionend', () => this._compositionHelper!.compositionend()));
420427
this._register(addDisposableListener(this.textarea!, 'input', (ev: InputEvent) => this._inputEvent(ev), true));

0 commit comments

Comments
 (0)