mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Add ILinkMatcherOptions.hoverEndCallback
This commit is contained in:
+6
-2
@@ -241,9 +241,13 @@ export interface ILinkMatcherOptions {
|
||||
*/
|
||||
validationCallback?: LinkMatcherValidationCallback;
|
||||
/**
|
||||
* A callback that fired when the mouse hovers over a link.
|
||||
* A callback that fires when the mouse hovers over a link.
|
||||
*/
|
||||
hoverCallback?: LinkMatcherHandler;
|
||||
hoverStartCallback?: LinkMatcherHandler;
|
||||
/**
|
||||
* A callback that fires when the mouse leaves a link that was hovered.
|
||||
*/
|
||||
hoverEndCallback?: () => void;
|
||||
/**
|
||||
* The priority of the link matcher, this defines the order in which the link
|
||||
* matcher is evaluated relative to others, from highest to lowest. The
|
||||
|
||||
+9
-3
@@ -133,7 +133,8 @@ export class Linkifier {
|
||||
handler,
|
||||
matchIndex: options.matchIndex,
|
||||
validationCallback: options.validationCallback,
|
||||
hoverCallback: options.hoverCallback,
|
||||
hoverStartCallback: options.hoverStartCallback,
|
||||
hoverEndCallback: options.hoverEndCallback,
|
||||
priority: options.priority || 0
|
||||
};
|
||||
this._addLinkMatcherToList(matcher);
|
||||
@@ -259,8 +260,13 @@ export class Linkifier {
|
||||
window.open(uri, '_blank');
|
||||
},
|
||||
e => {
|
||||
if (matcher.hoverCallback) {
|
||||
return matcher.hoverCallback(e, uri);
|
||||
if (matcher.hoverStartCallback) {
|
||||
matcher.hoverStartCallback(e, uri);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
if (matcher.hoverEndCallback) {
|
||||
matcher.hoverEndCallback();
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
+2
-1
@@ -6,7 +6,8 @@ export type LinkMatcher = {
|
||||
id: number,
|
||||
regex: RegExp,
|
||||
handler: LinkMatcherHandler,
|
||||
hoverCallback?: LinkMatcherHandler,
|
||||
hoverStartCallback?: LinkMatcherHandler,
|
||||
hoverEndCallback?: () => void,
|
||||
matchIndex?: number,
|
||||
validationCallback?: LinkMatcherValidationCallback,
|
||||
priority?: number
|
||||
|
||||
@@ -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
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+7
-2
@@ -141,9 +141,14 @@ interface ILinkMatcherOptions {
|
||||
validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void;
|
||||
|
||||
/**
|
||||
* A callback that fired when the mouse hovers over a link.
|
||||
* A callback that fires when the mouse hovers over a link.
|
||||
*/
|
||||
hoverCallback?: (event: MouseEvent, uri: string) => boolean | void;
|
||||
hoverStartCallback?: (event: MouseEvent, uri: string) => boolean | void;
|
||||
|
||||
/**
|
||||
* A callback that fires when the mouse leaves a link that was hovered.
|
||||
*/
|
||||
hoverEndCallback?: (event: MouseEvent, uri: string) => boolean | void;
|
||||
|
||||
/**
|
||||
* The priority of the link matcher, this defines the order in which the link
|
||||
|
||||
Reference in New Issue
Block a user