Merge pull request #4087 from Tyriar/hyperlink_range

Expose range on link handler
This commit is contained in:
Daniel Imms
2022-08-30 07:08:06 -07:00
committed by GitHub
2 changed files with 23 additions and 19 deletions
+17 -16
View File
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
import { ILink, ILinkProvider } from 'browser/Types'; import { IBufferRange, ILink, ILinkProvider } from 'browser/Types';
import { CellData } from 'common/buffer/CellData'; import { CellData } from 'common/buffer/CellData';
import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services'; import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services';
@@ -54,24 +54,25 @@ export class OscLinkProvider implements ILinkProvider {
if (finishLink || (currentStart !== -1 && x === lineLength - 1)) { if (finishLink || (currentStart !== -1 && x === lineLength - 1)) {
const text = this._oscLinkService.getLinkData(currentLinkId)?.uri; const text = this._oscLinkService.getLinkData(currentLinkId)?.uri;
if (text) { 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 // OSC links always use underline and pointer decorations
result.push({ result.push({
text, text,
// These ranges are 1-based range,
range: { activate: (e, text) => (linkHandler?.activate(e, text, range) || defaultActivate(e, text)),
start: { hover: (e, text) => linkHandler?.hover?.(e, text, range),
x: currentStart + 1, leave: (e, text) => linkHandler?.leave?.(e, text, range)
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
}); });
} }
finishLink = false; finishLink = false;
+6 -3
View File
@@ -1117,8 +1117,9 @@ declare module 'xterm' {
* Calls when the link is activated. * Calls when the link is activated.
* @param event The mouse event triggering the callback. * @param event The mouse event triggering the callback.
* @param text The text of the link. * @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, * 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. * that will cause mouse events to not fall through and activate other links.
* @param event The mouse event triggering the callback. * @param event The mouse event triggering the callback.
* @param text The text of the link. * @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. * Called when the mouse leaves the link.
* @param event The mouse event triggering the callback. * @param event The mouse event triggering the callback.
* @param text The text of the link. * @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;
} }
/** /**