From 432c2cc36940fe8fce1fc67398d460a1c74570ff Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 8 Jun 2018 17:36:04 +0200 Subject: [PATCH 1/2] Nullify and remove mouse handlers when mouse move it exited Fixes #998 --- src/Terminal.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Terminal.ts b/src/Terminal.ts index 8a71df96..0bb8f7ee 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -1039,19 +1039,38 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II return this.cancel(ev); } + // TODO: Seems dangerous to attach event listeners to document, could they be done on element? + // TODO: All mouse handling should be pulled into its own file. + // bind events - if (this.normalMouse) on(this._document, 'mousemove', sendMove); + let moveHandler: (event: MouseEvent) => void; + if (this.normalMouse) { + moveHandler = (event: MouseEvent) => { + // Do nothing if normal mouse mode is on. This can happen if the mouse is held down when the + // terminal exits normalMouse mode. + if (!this.normalMouse) { + return; + } + sendMove(event); + }; + on(this._document, 'mousemove', moveHandler); + } // x10 compatibility mode can't send button releases if (!this.x10Mouse) { const handler = (ev: MouseEvent) => { - sendButton(ev); - // TODO: Seems dangerous calling this on document? - if (this.normalMouse) off(this._document, 'mousemove', sendMove); + if (this.normalMouse) { + sendButton(ev); + } + if (moveHandler) { + // Even though this should only be attached when this.normalMouse is true, holding the + // mouse button down when normalMouse changes can happen. Just always try to remove it. + off(this._document, 'mousemove', moveHandler); + moveHandler = null; + } off(this._document, 'mouseup', handler); return this.cancel(ev); }; - // TODO: Seems dangerous calling this on document? on(this._document, 'mouseup', handler); } From e24dca3e2923c3dbe2d067b637bc13ccb5a4c120 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 23 Jun 2018 17:00:53 +1000 Subject: [PATCH 2/2] Send mousemove events when x10Mouse is true --- src/Terminal.ts | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Terminal.ts b/src/Terminal.ts index b332581f..f0f15405 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -1002,7 +1002,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II return this.cancel(ev); } - // TODO: Seems dangerous to attach event listeners to document, could they be done on element? // TODO: All mouse handling should be pulled into its own file. // bind events @@ -1020,22 +1019,20 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II } // x10 compatibility mode can't send button releases - if (!this.x10Mouse) { - const handler = (ev: MouseEvent) => { - if (this.normalMouse) { - sendButton(ev); - } - if (moveHandler) { - // Even though this should only be attached when this.normalMouse is true, holding the - // mouse button down when normalMouse changes can happen. Just always try to remove it. - off(this._document, 'mousemove', moveHandler); - moveHandler = null; - } - off(this._document, 'mouseup', handler); - return this.cancel(ev); - }; - on(this._document, 'mouseup', handler); - } + const handler = (ev: MouseEvent) => { + if (this.normalMouse && !this.x10Mouse) { + sendButton(ev); + } + if (moveHandler) { + // Even though this should only be attached when this.normalMouse is true, holding the + // mouse button down when normalMouse changes can happen. Just always try to remove it. + off(this._document, 'mousemove', moveHandler); + moveHandler = null; + } + off(this._document, 'mouseup', handler); + return this.cancel(ev); + }; + on(this._document, 'mouseup', handler); return this.cancel(ev); });