Skip to content

Commit

Permalink
Merge pull request #1022 from Tyriar/1020_mouse_events_linkifier
Browse files Browse the repository at this point in the history
Ensure linkifier cancels mouse event when being handled
  • Loading branch information
Tyriar authored Oct 6, 2017
2 parents 635cf26 + 95f68a4 commit 5bf8193
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/input/MouseZoneManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class MouseZoneManager implements IMouseZoneManager {

private _areZonesActive: boolean = false;
private _mouseMoveListener: (e: MouseEvent) => any;
private _mouseDownListener: (e: MouseEvent) => any;
private _clickListener: (e: MouseEvent) => any;

private _tooltipTimeout: number = null;
Expand All @@ -31,6 +30,8 @@ export class MouseZoneManager implements IMouseZoneManager {
constructor(
private _terminal: ITerminal
) {
this._terminal.element.addEventListener('mousedown', e => this._onMouseDown(e));

// These events are expensive, only listen to it when mouse zones are active
this._mouseMoveListener = e => this._onMouseMove(e);
this._clickListener = e => this._onClick(e);
Expand Down Expand Up @@ -140,11 +141,30 @@ export class MouseZoneManager implements IMouseZoneManager {
}
}

private _onMouseDown(e: MouseEvent): void {
// Ignore the event if there are no zones active
if (!this._areZonesActive) {
return;
}

// Find the active zone, prevent event propagation if found to prevent other
// components from handling the mouse event.
const zone = this._findZoneEventAt(e);
if (zone) {
// TODO: When link modifier support is added, the event should only be
// cancelled when the modifier is held (see #1021)
e.preventDefault();
e.stopImmediatePropagation();
}
}

private _onClick(e: MouseEvent): void {
// Find the active zone and click it if found
const zone = this._findZoneEventAt(e);
if (zone) {
zone.clickCallback(e);
e.preventDefault();
e.stopImmediatePropagation();
}
}

Expand Down

0 comments on commit 5bf8193

Please sign in to comment.