From 6a717177513ad81662247ed580ae2023a4e1da13 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 23 Feb 2018 11:28:14 -0800 Subject: [PATCH] Allow customization of the web links handler and options --- src/addons/webLinks/webLinks.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/addons/webLinks/webLinks.ts b/src/addons/webLinks/webLinks.ts index 5e4ac029..7ff87c60 100644 --- a/src/addons/webLinks/webLinks.ts +++ b/src/addons/webLinks/webLinks.ts @@ -5,7 +5,7 @@ /// -import { Terminal } from 'xterm'; +import { Terminal, ILinkMatcherOptions } from 'xterm'; const protocolClause = '(https?:\\/\\/)'; const domainCharacterSet = '[\\da-z\\.-]+'; @@ -30,12 +30,19 @@ function handleLink(event: MouseEvent, uri: string): void { window.open(uri, '_blank'); } -export function webLinksInit(term: Terminal): void { - term.registerLinkMatcher(strictUrlRegex, handleLink, { matchIndex: 1 }); +/** + * Initialize the web links addon, registering the link matcher. + * @param term The terminal to use web links within. + * @param handler A custom handler to use. + * @param options Custom options to use, matchIndex will always be ignored. + */ +export function webLinksInit(term: Terminal, handler: (event: MouseEvent, uri: string) => void = handleLink, options: ILinkMatcherOptions = {}): void { + options.matchIndex = 1; + term.registerLinkMatcher(strictUrlRegex, handler, options); } export function apply(terminalConstructor: typeof Terminal): void { - (terminalConstructor.prototype).webLinksInit = function (): void { - webLinksInit(this); + (terminalConstructor.prototype).webLinksInit = function (handler?: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): void { + webLinksInit(this, handler, options); }; }