From 040f9f49d91251735e0dc2a78cad1b6d783ba7c4 Mon Sep 17 00:00:00 2001 From: Jon Bockhorst Date: Mon, 14 Oct 2019 14:25:02 -0500 Subject: [PATCH] Support link position in hover tooltip callback --- src/browser/Linkifier.ts | 2 +- src/browser/Types.d.ts | 12 ++++++++++-- typings/xterm.d.ts | 27 ++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/browser/Linkifier.ts b/src/browser/Linkifier.ts index 53a32aa7f..d17de1caa 100644 --- a/src/browser/Linkifier.ts +++ b/src/browser/Linkifier.ts @@ -306,7 +306,7 @@ export class Linkifier implements ILinkifier { e => { this._onLinkTooltip.fire(this._createLinkHoverEvent(x1, y1, x2, y2, fg)); if (matcher.hoverTooltipCallback) { - matcher.hoverTooltipCallback(e, uri); + matcher.hoverTooltipCallback(e, uri, { startRow: y1, startColumn: x1, endRow: y2, endColumn: x2 }); } }, () => { diff --git a/src/browser/Types.d.ts b/src/browser/Types.d.ts index 894beb36c..bd3d87225 100644 --- a/src/browser/Types.d.ts +++ b/src/browser/Types.d.ts @@ -43,14 +43,22 @@ export interface IViewport extends IDisposable { onThemeChange(colors: IColorSet): void; } +export interface ILinkLocation { + startColumn: number; + startRow: number; + endColumn: number; + endRow: number; +} + export type LinkMatcherHandler = (event: MouseEvent, uri: string) => void; +export type LinkMatcherHoverTooltipCallback = (event: MouseEvent, uri: string, position: ILinkLocation) => void; export type LinkMatcherValidationCallback = (uri: string, callback: (isValid: boolean) => void) => void; export interface ILinkMatcher { id: number; regex: RegExp; handler: LinkMatcherHandler; - hoverTooltipCallback?: LinkMatcherHandler; + hoverTooltipCallback?: LinkMatcherHoverTooltipCallback; hoverLeaveCallback?: () => void; matchIndex?: number; validationCallback?: LinkMatcherValidationCallback; @@ -96,7 +104,7 @@ export interface ILinkMatcherOptions { /** * A callback that fires when the mouse hovers over a link. */ - tooltipCallback?: LinkMatcherHandler; + tooltipCallback?: LinkMatcherHoverTooltipCallback; /** * A callback that fires when the mouse leaves a link that was hovered. */ diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 44ef66bda..2ea8706a7 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -269,7 +269,7 @@ declare module 'xterm' { /** * A callback that fires when the mouse hovers over a link for a moment. */ - tooltipCallback?: (event: MouseEvent, uri: string) => boolean | void; + tooltipCallback?: (event: MouseEvent, uri: string, location: ILinkLocation) => boolean | void; /** * A callback that fires when the mouse leaves a link. Note that this can @@ -842,6 +842,31 @@ declare module 'xterm' { endRow: number; } + /** + * An object representing a link location within the terminal. + */ + interface ILinkLocation { + /** + * The start column of the link. + */ + startColumn: number; + + /** + * The start row of the link. + */ + startRow: number; + + /** + * The end column of the link. + */ + endColumn: number; + + /** + * The end row of the link. + */ + endRow: number; + } + /** * Represents a terminal buffer. */