Add ILinkMatcherOptions.hoverEndCallback
This commit is contained in:
@@ -8,5 +8,6 @@ export interface IMouseZone {
|
||||
x2: number;
|
||||
y: number;
|
||||
clickCallback: (e: MouseEvent) => any;
|
||||
hoverCallback?: (e: MouseEvent) => any;
|
||||
hoverStartCallback?: (e: MouseEvent) => any;
|
||||
hoverEndCallback?: () => any;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ export class MouseZoneManager implements IMouseZoneManager {
|
||||
private _mouseDownListener: (e: MouseEvent) => any;
|
||||
private _clickListener: (e: MouseEvent) => any;
|
||||
|
||||
private _hoverTimeout: number;
|
||||
private _hoverTimeout: number = null;
|
||||
private _currentZone: IMouseZone = null;
|
||||
private _lastHoverCoords: [number, number] = [null, null];
|
||||
|
||||
constructor(
|
||||
@@ -60,11 +61,22 @@ export class MouseZoneManager implements IMouseZoneManager {
|
||||
}
|
||||
|
||||
private _onMouseMove(e: MouseEvent): void {
|
||||
// TODO: Ideally this would only clear the hover state when the mouse moves
|
||||
// outside of the mouse zone
|
||||
if (this._lastHoverCoords[0] !== e.pageX && this._lastHoverCoords[1] !== e.pageY) {
|
||||
// Restart the timeout
|
||||
if (this._hoverTimeout) {
|
||||
clearTimeout(this._hoverTimeout);
|
||||
}
|
||||
this._hoverTimeout = <number><any>setTimeout(() => this._onHover(e), HOVER_DURATION);
|
||||
|
||||
// Fire the hover end callback if a zone was being hovered
|
||||
if (this._currentZone) {
|
||||
this._currentZone.hoverEndCallback();
|
||||
this._currentZone = null;
|
||||
}
|
||||
|
||||
// Record the current coordinates
|
||||
this._lastHoverCoords = [e.pageX, e.pageY];
|
||||
}
|
||||
}
|
||||
@@ -72,8 +84,9 @@ export class MouseZoneManager implements IMouseZoneManager {
|
||||
private _onHover(e: MouseEvent): void {
|
||||
const coords = getCoords(e, this._terminal.element, this._terminal.charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows);
|
||||
const zone = this._findZoneEventAt(e);
|
||||
if (zone && zone.hoverCallback) {
|
||||
zone.hoverCallback(e);
|
||||
if (zone && zone.hoverStartCallback) {
|
||||
this._currentZone = zone;
|
||||
zone.hoverStartCallback(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +116,8 @@ export class MouseZone implements IMouseZone {
|
||||
public x2: number,
|
||||
public y: number,
|
||||
public clickCallback: (e: MouseEvent) => any,
|
||||
public hoverCallback?: (e: MouseEvent) => any
|
||||
public hoverStartCallback?: (e: MouseEvent) => any,
|
||||
public hoverEndCallback?: () => void
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user