diff --git a/src/Linkifier.ts b/src/Linkifier.ts index 8f011cb2..1cdf0f4a 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -229,19 +229,10 @@ export class Linkifier { * @param {string} uri The uri of the link. * @return {HTMLAnchorElement} The link. */ - private _createAnchorElement(uri: string, handler: LinkMatcherHandler): HTMLAnchorElement { + private _createAnchorElement(uri: string, handler: LinkMatcherHandler, isHypertextLinkHandler: boolean): HTMLAnchorElement { const element = this._document.createElement('a'); element.textContent = uri; - if (handler) { - element.addEventListener('click', (event: MouseEvent) => { - // Don't execute the handler if the link is flagged as invalid - if (element.classList.contains(INVALID_LINK_CLASS)) { - return; - } - - return handler(event, uri); - }); - } else { + if (isHypertextLinkHandler) { element.href = uri; // Force link on another tab so work is not lost element.target = '_blank'; @@ -250,6 +241,14 @@ export class Linkifier { return handler(event, uri); } }); + } else { + element.addEventListener('click', (event: MouseEvent) => { + // Don't execute the handler if the link is flagged as invalid + if (element.classList.contains(INVALID_LINK_CLASS)) { + return; + } + return handler(event, uri); + }); } return element; } diff --git a/src/Types.ts b/src/Types.ts index 634e2fdc..9e8cd762 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -10,5 +10,5 @@ export type LinkMatcher = { validationCallback?: LinkMatcherValidationCallback, priority?: number }; -export type LinkMatcherHandler = (event: MouseEvent, uri: string) => void; +export type LinkMatcherHandler = (event: MouseEvent, uri: string) => boolean | void; export type LinkMatcherValidationCallback = (uri: string, callback: (isValid: boolean) => void) => void; diff --git a/src/xterm.js b/src/xterm.js index a08e9dd1..37c00ed8 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1295,7 +1295,6 @@ Terminal.prototype.attachHypertextLinkHandler = function(handler) { this.refresh(0, this.rows - 1); } - /** * Registers a link matcher, allowing custom link patterns to be matched and * handled.