From 040f9f49d91251735e0dc2a78cad1b6d783ba7c4 Mon Sep 17 00:00:00 2001 From: Jon Bockhorst Date: Mon, 14 Oct 2019 14:25:02 -0500 Subject: [PATCH 1/4] 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 53a32aa7..d17de1ca 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 894beb36..bd3d8722 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 44ef66bd..2ea8706a 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. */ From 08475eb4954c1fff67ea0ab79bb21cd798d7ddfd Mon Sep 17 00:00:00 2001 From: Jon Bockhorst Date: Thu, 17 Oct 2019 12:25:42 -0500 Subject: [PATCH 2/4] Update API to use IViewportRange and IViewportCellPosition --- src/browser/Linkifier.ts | 2 +- src/browser/Types.d.ts | 15 +++++++++------ typings/xterm.d.ts | 33 +++++++++++++++++++-------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/browser/Linkifier.ts b/src/browser/Linkifier.ts index d17de1ca..0b51d43f 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, { startRow: y1, startColumn: x1, endRow: y2, endColumn: x2 }); + matcher.hoverTooltipCallback(e, uri, { start: { row: y1, col: x1 }, end: { row: y2, col: x2 } }); } }, () => { diff --git a/src/browser/Types.d.ts b/src/browser/Types.d.ts index bd3d8722..2b9a4a9b 100644 --- a/src/browser/Types.d.ts +++ b/src/browser/Types.d.ts @@ -43,15 +43,18 @@ export interface IViewport extends IDisposable { onThemeChange(colors: IColorSet): void; } -export interface ILinkLocation { - startColumn: number; - startRow: number; - endColumn: number; - endRow: number; +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: ILinkLocation) => void; +export type LinkMatcherHoverTooltipCallback = (event: MouseEvent, uri: string, position: IViewportRange) => void; export type LinkMatcherValidationCallback = (uri: string, callback: (isValid: boolean) => void) => void; export interface ILinkMatcher { diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 2ea8706a..32dce910 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, location: ILinkLocation) => 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 @@ -843,28 +843,33 @@ declare module 'xterm' { } /** - * An object representing a link location within the terminal. + * An object representing a range within the viewport of the terminal. */ - interface ILinkLocation { + interface IViewportRange { /** - * The start column of the link. + * The start cell of the range. */ - startColumn: number; + start: IViewportCellPosition; /** - * The start row of the link. + * The end cell of the range. */ - startRow: number; + end: IViewportCellPosition; + } + + /** + * An object representing a cell within the viewport of the terminal. + */ + interface IViewportCellPosition { + /** + * The column of the cell. + */ + col: number; /** - * The end column of the link. + * The row of the cell. */ - endColumn: number; - - /** - * The end row of the link. - */ - endRow: number; + row: number; } /** From 57581ca4ef4b80794eeed996c2b016e954429687 Mon Sep 17 00:00:00 2001 From: Jon Bockhorst Date: Thu, 17 Oct 2019 12:40:32 -0500 Subject: [PATCH 3/4] Updated IViewportCellPosition wording --- typings/xterm.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 32dce910..e7b2247e 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -858,7 +858,7 @@ declare module 'xterm' { } /** - * An object representing a cell within the viewport of the terminal. + * An object representing a cell position within the viewport of the terminal. */ interface IViewportCellPosition { /** From 83508048585ec5c7d5322c27d9d2c9f7d3949d86 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Oct 2019 12:36:03 -0700 Subject: [PATCH 4/4] Adjust to use 1-based, note in API --- src/browser/Linkifier.ts | 4 +++- typings/xterm.d.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/browser/Linkifier.ts b/src/browser/Linkifier.ts index 0b51d43f..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, { start: { row: y1, col: x1 }, end: { row: y2, col: x2 } }); + // 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/typings/xterm.d.ts b/typings/xterm.d.ts index e7b2247e..c1f5eab9 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -862,12 +862,12 @@ declare module 'xterm' { */ interface IViewportCellPosition { /** - * The column of the cell. + * The column of the cell. Note that this is 1-based; the first column is column 1. */ col: number; /** - * The row of the cell. + * The row of the cell. Note that this is 1-based; the first row is row 1. */ row: number; }