Get multi-line link hover working

This commit is contained in:
Daniel Imms
2018-03-08 06:42:40 -08:00
parent 7a1ef19146
commit f456b14b3f
3 changed files with 22 additions and 7 deletions
+3 -2
View File
@@ -27,7 +27,7 @@ export class Linkifier extends EventEmitter implements ILinkifier {
private _rowsToLinkify: {start: number, end: number}; private _rowsToLinkify: {start: number, end: number};
constructor( constructor(
protected _terminal: IBufferAccessor & IElementAccessor protected _terminal: ITerminal
) { ) {
super(); super();
this._rowsToLinkify = { this._rowsToLinkify = {
@@ -236,8 +236,9 @@ export class Linkifier extends EventEmitter implements ILinkifier {
// TODO: Make MouseZone's work over multiple lines // TODO: Make MouseZone's work over multiple lines
this._mouseZoneManager.add(new MouseZone( this._mouseZoneManager.add(new MouseZone(
x + 1, x + 1,
x + 1 + uri.length,
y + 1, y + 1,
(x + 1 + uri.length) % this._terminal.cols,
y + 1 + Math.floor((x + 1 + uri.length) / this._terminal.cols),
e => { e => {
if (matcher.handler) { if (matcher.handler) {
return matcher.handler(e, uri); return matcher.handler(e, uri);
+17 -4
View File
@@ -59,7 +59,7 @@ export class MouseZoneManager implements IMouseZoneManager {
// Iterate through zones and clear them out if they're within the range // Iterate through zones and clear them out if they're within the range
for (let i = 0; i < this._zones.length; i++) { for (let i = 0; i < this._zones.length; i++) {
const zone = this._zones[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) { if (this._currentZone && this._currentZone === zone) {
this._currentZone.leaveCallback(); this._currentZone.leaveCallback();
this._currentZone = null; this._currentZone = null;
@@ -173,10 +173,22 @@ export class MouseZoneManager implements IMouseZoneManager {
if (!coords) { if (!coords) {
return null; return null;
} }
const x = coords[0];
const y = coords[1];
for (let i = 0; i < this._zones.length; i++) { for (let i = 0; i < this._zones.length; i++) {
const zone = this._zones[i]; const zone = this._zones[i];
if (zone.y === coords[1] && zone.x1 <= coords[0] && zone.x2 > coords[0]) { if (zone.y1 === zone.y2) {
return zone; // 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; return null;
@@ -186,8 +198,9 @@ export class MouseZoneManager implements IMouseZoneManager {
export class MouseZone implements IMouseZone { export class MouseZone implements IMouseZone {
constructor( constructor(
public x1: number, public x1: number,
public y1: number,
public x2: number, public x2: number,
public y: number, public y2: number,
public clickCallback: (e: MouseEvent) => any, public clickCallback: (e: MouseEvent) => any,
public hoverCallback: (e: MouseEvent) => any, public hoverCallback: (e: MouseEvent) => any,
public tooltipCallback: (e: MouseEvent) => any, public tooltipCallback: (e: MouseEvent) => any,
+2 -1
View File
@@ -11,7 +11,8 @@ export interface IMouseZoneManager {
export interface IMouseZone { export interface IMouseZone {
x1: number; x1: number;
x2: number; x2: number;
y: number; y1: number;
y2: number;
clickCallback: (e: MouseEvent) => any; clickCallback: (e: MouseEvent) => any;
hoverCallback: (e: MouseEvent) => any | undefined; hoverCallback: (e: MouseEvent) => any | undefined;
tooltipCallback: (e: MouseEvent) => any | undefined; tooltipCallback: (e: MouseEvent) => any | undefined;