Remove link matchers

Fixes #2703
This commit is contained in:
Daniel Imms
2022-07-27 06:49:35 -07:00
parent fafa7efd5e
commit 7a17a26e18
15 changed files with 23 additions and 961 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
* @license MIT
*/
import { Terminal, ILinkMatcherOptions, ITerminalAddon } from 'xterm';
import { Terminal, ITerminalAddon } from 'xterm';
declare module 'xterm-addon-attach' {
export interface IAttachOptions {
@@ -3,7 +3,7 @@
* @license MIT
*/
import { Terminal, ILinkMatcherOptions, ITerminalAddon, IDisposable } from 'xterm';
import { Terminal, ITerminalAddon, IDisposable } from 'xterm';
import { ILinkProviderOptions, WebLinkProvider } from './WebLinkProvider';
const protocolClause = '(https?:\\/\\/)';
@@ -41,37 +41,23 @@ function handleLink(event: MouseEvent, uri: string): void {
}
export class WebLinksAddon implements ITerminalAddon {
private _linkMatcherId: number | undefined;
private _terminal: Terminal | undefined;
private _linkProvider: IDisposable | undefined;
constructor(
private _handler: (event: MouseEvent, uri: string) => void = handleLink,
private _options: ILinkMatcherOptions | ILinkProviderOptions = {},
private _useLinkProvider: boolean = false
private _options: ILinkProviderOptions = {}
) {
}
public activate(terminal: Terminal): void {
this._terminal = terminal;
if (this._useLinkProvider && 'registerLinkProvider' in this._terminal) {
const options = this._options as ILinkProviderOptions;
const regex = options.urlRegex || strictUrlRegex;
this._linkProvider = this._terminal.registerLinkProvider(new WebLinkProvider(this._terminal, regex, this._handler, options));
} else {
// TODO: This should be removed eventually
const options = this._options as ILinkMatcherOptions;
options.matchIndex = 1;
this._linkMatcherId = (this._terminal as Terminal).registerLinkMatcher(strictUrlRegex, this._handler, options);
}
const options = this._options as ILinkProviderOptions;
const regex = options.urlRegex || strictUrlRegex;
this._linkProvider = this._terminal.registerLinkProvider(new WebLinkProvider(this._terminal, regex, this._handler, options));
}
public dispose(): void {
if (this._linkMatcherId !== undefined && this._terminal !== undefined) {
this._terminal.deregisterLinkMatcher(this._linkMatcherId);
}
this._linkProvider?.dispose();
}
}
@@ -4,7 +4,7 @@
*/
import { Terminal, ILinkMatcherOptions, ITerminalAddon, IViewportRange } from 'xterm';
import { Terminal, ITerminalAddon, IViewportRange } from 'xterm';
declare module 'xterm-addon-web-links' {
/**
@@ -14,13 +14,9 @@ declare module 'xterm-addon-web-links' {
/**
* Creates a new web links addon.
* @param handler The callback when the link is called.
* @param options Options for the link matcher.
* @param useLinkProvider Whether to use the new link provider API to create
* the links. This is an option because use of both link matcher (old) and
* link provider (new) may cause issues. Link provider will eventually be
* the default and only option.
* @param options Options for the link provider.
*/
constructor(handler?: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions | ILinkProviderOptions, useLinkProvider?: boolean);
constructor(handler?: (event: MouseEvent, uri: string) => void, options?: ILinkProviderOptions);
/**
* Activates the addon
@@ -50,7 +46,7 @@ declare module 'xterm-addon-web-links' {
*/
leave?(event: MouseEvent, text: string): void;
/**
/**
* A callback to use instead of the default one.
*/
urlRegex?: RegExp;
@@ -15,8 +15,6 @@ export class LinkRenderLayer extends BaseRenderLayer {
constructor(container: HTMLElement, zIndex: number, colors: IColorSet, terminal: ITerminal) {
super(container, 'link', zIndex, true, colors);
terminal.linkifier.onShowLinkUnderline(e => this._onShowLinkUnderline(e));
terminal.linkifier.onHideLinkUnderline(e => this._onHideLinkUnderline(e));
terminal.linkifier2.onShowLinkUnderline(e => this._onShowLinkUnderline(e));
terminal.linkifier2.onHideLinkUnderline(e => this._onHideLinkUnderline(e));