diff --git a/src/Linkifier.ts b/src/Linkifier.ts index 745c64de..b9cdaaa3 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -27,7 +27,7 @@ export class Linkifier extends EventEmitter implements ILinkifier { private _rowsToLinkify: {start: number, end: number}; constructor( - protected _terminal: IBufferAccessor & IElementAccessor + protected _terminal: ITerminal ) { super(); this._rowsToLinkify = { @@ -236,8 +236,9 @@ export class Linkifier extends EventEmitter implements ILinkifier { // TODO: Make MouseZone's work over multiple lines this._mouseZoneManager.add(new MouseZone( x + 1, - x + 1 + uri.length, y + 1, + (x + 1 + uri.length) % this._terminal.cols, + y + 1 + Math.floor((x + 1 + uri.length) / this._terminal.cols), e => { if (matcher.handler) { return matcher.handler(e, uri); diff --git a/src/input/MouseZoneManager.ts b/src/input/MouseZoneManager.ts index 3ab86e7c..76a5a366 100644 --- a/src/input/MouseZoneManager.ts +++ b/src/input/MouseZoneManager.ts @@ -59,7 +59,7 @@ export class MouseZoneManager implements IMouseZoneManager { // Iterate through zones and clear them out if they're within the range for (let i = 0; i < this._zones.length; i++) { const zone = this._zones[i]; - if (zone.y > start && zone.y <= end + 1) { + if (zone.y1 > start && zone.y1 <= end + 1) { if (this._currentZone && this._currentZone === zone) { this._currentZone.leaveCallback(); this._currentZone = null; @@ -173,10 +173,22 @@ export class MouseZoneManager implements IMouseZoneManager { if (!coords) { return null; } + const x = coords[0]; + const y = coords[1]; for (let i = 0; i < this._zones.length; i++) { const zone = this._zones[i]; - if (zone.y === coords[1] && zone.x1 <= coords[0] && zone.x2 > coords[0]) { - return zone; + if (zone.y1 === zone.y2) { + // Single line link + if (y === zone.y1 && x >= zone.x1 && x < zone.x2) { + return zone; + } + } else { + // Multi-line link + if ((y === zone.y1 && x >= zone.x1) || + (y === zone.y2 && x < zone.x2) || + (y > zone.y1 && y < zone.y2)) { + return zone; + } } } return null; @@ -186,8 +198,9 @@ export class MouseZoneManager implements IMouseZoneManager { export class MouseZone implements IMouseZone { constructor( public x1: number, + public y1: number, public x2: number, - public y: number, + public y2: number, public clickCallback: (e: MouseEvent) => any, public hoverCallback: (e: MouseEvent) => any, public tooltipCallback: (e: MouseEvent) => any, diff --git a/src/input/Types.ts b/src/input/Types.ts index f1398464..2bd805bf 100644 --- a/src/input/Types.ts +++ b/src/input/Types.ts @@ -11,7 +11,8 @@ export interface IMouseZoneManager { export interface IMouseZone { x1: number; x2: number; - y: number; + y1: number; + y2: number; clickCallback: (e: MouseEvent) => any; hoverCallback: (e: MouseEvent) => any | undefined; tooltipCallback: (e: MouseEvent) => any | undefined;