From 7e5592d71027ca2e2cd7c2d33c5bc6fb5f1f2098 Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Wed, 11 Sep 2019 19:44:46 +0200 Subject: [PATCH] Let the right mouse button go through to apps when mouse events are used --- extraterm/src/render_process/Terminal.ts | 16 +++++----- .../viewers/TerminalAceViewer.ts | 31 +++++++++++++++---- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/extraterm/src/render_process/Terminal.ts b/extraterm/src/render_process/Terminal.ts index c3ec9d93a..a6ab43c7a 100644 --- a/extraterm/src/render_process/Terminal.ts +++ b/extraterm/src/render_process/Terminal.ts @@ -212,9 +212,7 @@ export class EtTerminal extends ThemeableElementBase implements AcceptsKeybindin this.updateThemeCss(); - this._terminalCanvas.addEventListener('mousedown', ev => this._handleMouseDownCapture(ev), true); - this._terminalCanvas.addEventListener("contextmenu", (ev) => this._handleContextMenu(ev)); - + this._terminalCanvas.addEventListener('mousedown', ev => this._handleMouseDownCapture(ev)); this._terminalCanvas.addEventListener(GeneralEvents.EVENT_TYPE_TEXT, (ev: CustomEvent) => { const detail: GeneralEvents.TypeTextEventDetail = ev.detail; this.sendToPty(detail.text); @@ -664,13 +662,13 @@ export class EtTerminal extends ThemeableElementBase implements AcceptsKeybindin ev.preventDefault(); this._pasteFromClipboard(); } - } - private _handleContextMenu(ev: MouseEvent): void { - if (this._terminalViewer !== null) { - ev.stopPropagation(); - ev.preventDefault(); - dispatchContextMenuRequest(this._terminalViewer, ev.x, ev.y); + if ((ev.buttons & 2) !== 0) { + if (this._terminalViewer !== null) { + ev.stopPropagation(); + ev.preventDefault(); + dispatchContextMenuRequest(this._terminalViewer, ev.x, ev.y); + } } } diff --git a/extraterm/src/render_process/viewers/TerminalAceViewer.ts b/extraterm/src/render_process/viewers/TerminalAceViewer.ts index e51aec193..3b0166c21 100644 --- a/extraterm/src/render_process/viewers/TerminalAceViewer.ts +++ b/extraterm/src/render_process/viewers/TerminalAceViewer.ts @@ -264,7 +264,6 @@ export class TerminalViewer extends ViewerElement implements SupportsClipboardPa // Filter the keyboard events before they reach Ace. containerDiv.addEventListener('keydown', ev => this._handleContainerKeyDownCapture(ev), true); - containerDiv.addEventListener('contextmenu', ev => this._handleContextMenu(ev)); const aceElement = this._aceEditor.renderer.scrollerElement; aceElement.addEventListener("mousedown", ev => this._handleMouseDownEvent(ev), true); @@ -1055,19 +1054,19 @@ export class TerminalViewer extends ViewerElement implements SupportsClipboardPa this._aceEditSession.setScrollTopPx(yCoord); } - private _handleEmulatorMouseEvent(ev: MouseEvent, emulatorHandler: (opts: TermApi.MouseEventOptions) => boolean): void { + private _handleEmulatorMouseEvent(ev: MouseEvent, emulatorHandler: (opts: TermApi.MouseEventOptions) => boolean): boolean { // Ctrl click prevents the mouse being taken over by // the application and allows the user to select stuff. if (ev.ctrlKey) { - return; + return false; } const pos = this._aceEditor.renderer.screenToTextCoordinates(ev.clientX, ev.clientY); if (pos === null) { - return; + return false; } if (pos.row - this._terminalFirstRow < 0) { // Don't send mouse events for stuff which happens in the scrollback area. - return; + return false; } // send the buttons @@ -1086,20 +1085,40 @@ export class TerminalViewer extends ViewerElement implements SupportsClipboardPa // The emulator consumed the event. Stop Ace from processing it too. ev.stopPropagation(); ev.preventDefault(); + return true; } + return false; } private _handleMouseDownEvent(ev: MouseEvent): void { + const isRightMouseButton = (ev.buttons & 2) !== 0; + if (isRightMouseButton) { + ev.preventDefault(); + ev.stopPropagation(); + } + if (this._emulator === null) { return; } if ( ! this.hasFocus()) { this.focus(); } - this._handleEmulatorMouseEvent(ev, this._emulator.mouseDown.bind(this._emulator)); + if (this._handleEmulatorMouseEvent(ev, this._emulator.mouseDown.bind(this._emulator))) { + return; + } + + if (isRightMouseButton) { + this._handleContextMenu(ev); + } } private _handleMouseUpEvent(ev: MouseEvent): void { + const isRightMouseButton = (ev.buttons & 2) !== 0; + if (isRightMouseButton) { + ev.preventDefault(); + ev.stopPropagation(); + } + if (this._emulator === null) { return; }