Skip to content

Commit

Permalink
Let the right mouse button go through to apps when mouse events are used
Browse files Browse the repository at this point in the history
  • Loading branch information
sedwards2009 committed Sep 11, 2019
1 parent d8129da commit 7e5592d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
16 changes: 7 additions & 9 deletions extraterm/src/render_process/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
31 changes: 25 additions & 6 deletions extraterm/src/render_process/viewers/TerminalAceViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit 7e5592d

Please sign in to comment.