From c5ba1d62e7a6375938026ede64ff09d6e1ac2528 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 25 Apr 2020 13:31:45 -0700 Subject: [PATCH] Remove mouseEvents from Terminal Depend on CoreMouseService directly --- src/Terminal.ts | 12 ++++-------- src/common/TestUtils.test.ts | 1 + src/common/services/CoreMouseService.ts | 4 ++++ src/common/services/Services.ts | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Terminal.ts b/src/Terminal.ts index bb02671fd..c88a07150 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -88,9 +88,6 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT private _selectionService: ISelectionService; private _soundService: ISoundService; - // mouse properties - public mouseEvents: CoreMouseEventType = CoreMouseEventType.NONE; - // write buffer private _writeBuffer: WriteBuffer; @@ -500,7 +497,7 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this._selectionService.onMouseDown(e))); // apply mouse event classes set by escape codes before terminal was attached - if (this.mouseEvents) { + if (this._coreMouseService.areMouseEventsActive) { this._selectionService.disable(); this.element.classList.add('enable-mouse-events'); } else { @@ -675,7 +672,6 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT }; this._coreMouseService.onProtocolChange(events => { // apply global changes on events - this.mouseEvents = events; if (events) { if (this.optionsService.options.logLevel === 'debug') { this._logService.debug('Binding to mouse events:', this._coreMouseService.explainEvents(events)); @@ -733,7 +729,7 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT // Don't send the mouse button to the pty if mouse events are disabled or // if the selection manager is having selection forced (ie. a modifier is // held). - if (!this.mouseEvents || this._selectionService.shouldForceSelection(ev)) { + if (!this._coreMouseService.areMouseEventsActive || this._selectionService.shouldForceSelection(ev)) { return; } @@ -787,13 +783,13 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT })); this.register(addDisposableDomListener(el, 'touchstart', (ev: TouchEvent) => { - if (this.mouseEvents) return; + if (this._coreMouseService.areMouseEventsActive) return; this.viewport.onTouchStart(ev); return this.cancel(ev); })); this.register(addDisposableDomListener(el, 'touchmove', (ev: TouchEvent) => { - if (this.mouseEvents) return; + if (this._coreMouseService.areMouseEventsActive) return; if (!this.viewport.onTouchMove(ev)) { return this.cancel(ev); } diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 55df896ee..e5b3a4258 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -31,6 +31,7 @@ export class MockBufferService implements IBufferService { } export class MockCoreMouseService implements ICoreMouseService { + public areMouseEventsActive: boolean = false; public activeEncoding: string = ''; public activeProtocol: string = ''; public addEncoding(name: string): void {} diff --git a/src/common/services/CoreMouseService.ts b/src/common/services/CoreMouseService.ts index c0ed3c6a4..29a847615 100644 --- a/src/common/services/CoreMouseService.ts +++ b/src/common/services/CoreMouseService.ts @@ -192,6 +192,10 @@ export class CoreMouseService implements ICoreMouseService { return this._activeProtocol; } + public get areMouseEventsActive(): boolean { + return this._protocols[this._activeProtocol].events !== 0; + } + public set activeProtocol(name: string) { if (!this._protocols[name]) { throw new Error(`unknown protocol "${name}"`); diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 62ab45fd8..05a6f3ae5 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -27,6 +27,7 @@ export const ICoreMouseService = createDecorator('CoreMouseSe export interface ICoreMouseService { activeProtocol: string; activeEncoding: string; + areMouseEventsActive: boolean; addProtocol(name: string, protocol: ICoreMouseProtocol): void; addEncoding(name: string, encoding: CoreMouseEncoding): void; reset(): void;