Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/browser/Linkifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a change to expose this as a 1-based number to align with https://invisible-island.net/xterm/ctlseqs/ctlseqs.html. It's looks a little weird how the end col doesn't add 1 but I guess that's how the mouse zones work right now, they include everything up to but excluding the end cell

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you forget col: x2 here? Shouldn't it be col: x2 + 1 as like the others?

}
},
() => {
Expand Down
15 changes: 13 additions & 2 deletions src/browser/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down
32 changes: 31 additions & 1 deletion typings/xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down