From 56a6a010ab3007043cc6b8cf0839cbfd81b275b8 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 20 Dec 2023 07:28:26 -0800 Subject: [PATCH] Fix crosshair cursor now working in some embedders This was not happening in the demo because the xterm instance is almost always focused. See microsoft/vscode#199848 --- src/browser/Terminal.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index 7e1f9014a6..01dfbc89cd 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -261,11 +261,10 @@ export class Terminal extends CoreTerminal implements ITerminal { /** * Binds the desired focus behavior on a given terminal object. */ - private _handleTextAreaFocus(ev: KeyboardEvent): void { + private _handleTextAreaFocus(ev: FocusEvent): void { if (this.coreService.decPrivateModes.sendFocus) { this.coreService.triggerDataEvent(C0.ESC + '[I'); } - this.updateCursorStyle(ev); this.element!.classList.add('focus'); this._showCursor(); this._onFocus.fire(); @@ -429,6 +428,7 @@ export class Terminal extends CoreTerminal implements ITerminal { this.screenElement = this._document.createElement('div'); this.screenElement.classList.add('xterm-screen'); + this.register(addDisposableDomListener(this.screenElement, 'mousemove', (ev: MouseEvent) => this.updateCursorStyle(ev))); // Create the container that will hold helpers like the textarea for // capturing DOM Events. Then produce the helpers. this._helperContainer = this._document.createElement('div'); @@ -459,11 +459,10 @@ export class Terminal extends CoreTerminal implements ITerminal { )); this._instantiationService.setService(ICoreBrowserService, this._coreBrowserService); - this.register(addDisposableDomListener(this.textarea, 'focus', (ev: KeyboardEvent) => this._handleTextAreaFocus(ev))); + this.register(addDisposableDomListener(this.textarea, 'focus', (ev: FocusEvent) => this._handleTextAreaFocus(ev))); this.register(addDisposableDomListener(this.textarea, 'blur', () => this._handleTextAreaBlur())); this._helperContainer.appendChild(this.textarea); - this._charSizeService = this._instantiationService.createInstance(CharSizeService, this._document, this._helperContainer); this._instantiationService.setService(ICharSizeService, this._charSizeService); @@ -855,7 +854,7 @@ export class Terminal extends CoreTerminal implements ITerminal { /** * Change the cursor style for different selection modes */ - public updateCursorStyle(ev: KeyboardEvent): void { + public updateCursorStyle(ev: KeyboardEvent | MouseEvent): void { if (this._selectionService?.shouldColumnSelect(ev)) { this.element!.classList.add('column-select'); } else {