diff --git a/src/browser/Linkifier.ts b/src/browser/Linkifier.ts index 53a32aa7..ecaf8af9 100644 --- a/src/browser/Linkifier.ts +++ b/src/browser/Linkifier.ts @@ -306,7 +306,9 @@ export class Linkifier implements ILinkifier { e => { this._onLinkTooltip.fire(this._createLinkHoverEvent(x1, y1, x2, y2, fg)); if (matcher.hoverTooltipCallback) { - matcher.hoverTooltipCallback(e, uri); + // Note that IViewportRange use 1-based coordinates to align with escape sequences such + // as CUP which use 1,1 as the default for row/col + matcher.hoverTooltipCallback(e, uri, { start: { row: y1 + 1, col: x1 + 1 }, end: { row: y2 + 1, col: x2 } }); } }, () => { diff --git a/src/browser/Types.d.ts b/src/browser/Types.d.ts index 692d6b03..274fc16f 100644 --- a/src/browser/Types.d.ts +++ b/src/browser/Types.d.ts @@ -43,14 +43,25 @@ export interface IViewport extends IDisposable { onThemeChange(colors: IColorSet): void; } +export interface IViewportRange { + start: IViewportCellPosition; + end: IViewportCellPosition; +} + +export interface IViewportCellPosition { + col: number; + row: number; +} + export type LinkMatcherHandler = (event: MouseEvent, uri: string) => void; +export type LinkMatcherHoverTooltipCallback = (event: MouseEvent, uri: string, position: IViewportRange) => 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 +107,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 bd222d6c..af7d5ca8 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -279,7 +279,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: IViewportRange) => boolean | void; /** * A callback that fires when the mouse leaves a link. Note that this can @@ -852,6 +852,36 @@ declare module 'xterm' { endRow: number; } + /** + * An object representing a range within the viewport of the terminal. + */ + interface IViewportRange { + /** + * The start cell of the range. + */ + start: IViewportCellPosition; + + /** + * The end cell of the range. + */ + end: IViewportCellPosition; + } + + /** + * An object representing a cell position within the viewport of the terminal. + */ + interface IViewportCellPosition { + /** + * The column of the cell. Note that this is 1-based; the first column is column 1. + */ + col: number; + + /** + * The row of the cell. Note that this is 1-based; the first row is row 1. + */ + row: number; + } + /** * Represents a terminal buffer. */