diff --git a/src/browser/OscLinkProvider.ts b/src/browser/OscLinkProvider.ts index 38c0710681..fdae9b0ee9 100644 --- a/src/browser/OscLinkProvider.ts +++ b/src/browser/OscLinkProvider.ts @@ -6,6 +6,7 @@ import { ILink, ILinkProvider } from 'browser/Types'; import { CellData } from 'common/buffer/CellData'; import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services'; +import { IBufferRange } from 'xterm'; export class OscLinkProvider implements ILinkProvider { constructor( @@ -54,24 +55,25 @@ export class OscLinkProvider implements ILinkProvider { if (finishLink || (currentStart !== -1 && x === lineLength - 1)) { const text = this._oscLinkService.getLinkData(currentLinkId)?.uri; if (text) { + // These ranges are 1-based + const range: IBufferRange = { + start: { + x: currentStart + 1, + y + }, + end: { + // Offset end x if it's a link that ends on the last cell in the line + x: x + (!finishLink && x === lineLength - 1 ? 1 : 0), + y + } + }; // OSC links always use underline and pointer decorations result.push({ text, - // These ranges are 1-based - range: { - start: { - x: currentStart + 1, - y - }, - end: { - // Offset end x if it's a link that ends on the last cell in the line - x: x + (!finishLink && x === lineLength - 1 ? 1 : 0), - y - } - }, - activate: linkHandler?.activate || defaultActivate, - hover: linkHandler?.hover, - leave: linkHandler?.leave + range, + activate: (e, text) => (linkHandler?.activate(e, text, range) || defaultActivate(e, text)), + hover: (e, text) => linkHandler?.hover?.(e, text, range), + leave: (e, text) => linkHandler?.leave?.(e, text, range) }); } finishLink = false; diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 2fa1742174..bd48afd4f2 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -1117,8 +1117,9 @@ declare module 'xterm' { * Calls when the link is activated. * @param event The mouse event triggering the callback. * @param text The text of the link. + * @param range The buffer range of the link. */ - activate(event: MouseEvent, text: string): void; + activate(event: MouseEvent, text: string, range: IBufferRange): void; /** * Called when the mouse hovers the link. To use this to create a DOM-based hover tooltip, @@ -1126,15 +1127,17 @@ declare module 'xterm' { * that will cause mouse events to not fall through and activate other links. * @param event The mouse event triggering the callback. * @param text The text of the link. + * @param range The buffer range of the link. */ - hover?(event: MouseEvent, text: string): void; + hover?(event: MouseEvent, text: string, range: IBufferRange): void; /** * Called when the mouse leaves the link. * @param event The mouse event triggering the callback. * @param text The text of the link. + * @param range The buffer range of the link. */ - leave?(event: MouseEvent, text: string): void; + leave?(event: MouseEvent, text: string, range: IBufferRange): void; } /**