Remove link caching
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { ILinkProvider, IBufferCellPosition, ILink, Terminal, IBuffer } from 'xterm';
|
import { ILinkProvider, IBufferCellPosition, ILink, Terminal, IBuffer } from 'xterm';
|
||||||
|
|
||||||
export default class WebLinkProvider implements ILinkProvider {
|
export class WebLinkProvider implements ILinkProvider {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _terminal: Terminal,
|
private readonly _terminal: Terminal,
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Terminal, ILinkMatcherOptions, ITerminalAddon, ILinkProvider } from 'xterm';
|
import { Terminal, ILinkMatcherOptions, ITerminalAddon, ILinkProvider, IDisposable } from 'xterm';
|
||||||
import WebLinkProvider from './WebLinkProvider';
|
import { WebLinkProvider } from './WebLinkProvider';
|
||||||
|
|
||||||
const protocolClause = '(https?:\\/\\/)';
|
const protocolClause = '(https?:\\/\\/)';
|
||||||
const domainCharacterSet = '[\\da-z\\.-]+';
|
const domainCharacterSet = '[\\da-z\\.-]+';
|
||||||
@@ -33,7 +33,7 @@ function handleLink(event: MouseEvent, uri: string): void {
|
|||||||
export class WebLinksAddon implements ITerminalAddon {
|
export class WebLinksAddon implements ITerminalAddon {
|
||||||
private _linkMatcherId: number | undefined;
|
private _linkMatcherId: number | undefined;
|
||||||
private _terminal: Terminal | undefined;
|
private _terminal: Terminal | undefined;
|
||||||
private _linkProvider: ILinkProvider | undefined;
|
private _linkProvider: IDisposable | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _handler: (event: MouseEvent, uri: string) => void = handleLink,
|
private _handler: (event: MouseEvent, uri: string) => void = handleLink,
|
||||||
@@ -46,8 +46,7 @@ export class WebLinksAddon implements ITerminalAddon {
|
|||||||
this._terminal = terminal;
|
this._terminal = terminal;
|
||||||
|
|
||||||
if ('registerLinkProvider' in this._terminal as any) {
|
if ('registerLinkProvider' in this._terminal as any) {
|
||||||
this._linkProvider = new WebLinkProvider(this._terminal, strictUrlRegex, this._handler);
|
this._linkProvider = this._terminal.registerLinkProvider(new WebLinkProvider(this._terminal, strictUrlRegex, this._handler));
|
||||||
this._terminal.registerLinkProvider(this._linkProvider);
|
|
||||||
} else {
|
} else {
|
||||||
this._linkMatcherId = this._terminal.registerLinkMatcher(strictUrlRegex, this._handler, this._options);
|
this._linkMatcherId = this._terminal.registerLinkMatcher(strictUrlRegex, this._handler, this._options);
|
||||||
}
|
}
|
||||||
@@ -57,5 +56,9 @@ export class WebLinksAddon implements ITerminalAddon {
|
|||||||
if (this._linkMatcherId !== undefined && this._terminal !== undefined) {
|
if (this._linkMatcherId !== undefined && this._terminal !== undefined) {
|
||||||
this._terminal.deregisterLinkMatcher(this._linkMatcherId);
|
this._terminal.deregisterLinkMatcher(this._linkMatcherId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._linkProvider) {
|
||||||
|
this._linkProvider.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1171,9 +1171,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
}
|
}
|
||||||
|
|
||||||
public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
|
public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
|
||||||
if (!this.linkifier2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return this.linkifier2.registerLinkProvider(linkProvider);
|
return this.linkifier2.registerLinkProvider(linkProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
import { ILinkifier2, ILinkProvider, IBufferCellPosition, ILink, ILinkifierEvent, IBufferRange } from './Types';
|
import { ILinkifier2, ILinkProvider, IBufferCellPosition, ILink, ILinkifierEvent, IBufferRange } from './Types';
|
||||||
import { IDisposable } from 'common/Types';
|
import { IDisposable } from 'common/Types';
|
||||||
import { IMouseService } from './services/Services';
|
import { IMouseService } from './services/Services';
|
||||||
import { IBufferService, ICoreService } from 'common/services/Services';
|
import { IBufferService, ICoreService } from 'common/services/Services';
|
||||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
||||||
* @license MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
export class Linkifier2 implements ILinkifier2 {
|
export class Linkifier2 implements ILinkifier2 {
|
||||||
private _element: HTMLElement | undefined;
|
private _element: HTMLElement | undefined;
|
||||||
private _viewportElement: HTMLElement | undefined;
|
private _viewportElement: HTMLElement | undefined;
|
||||||
@@ -69,21 +66,13 @@ export class Linkifier2 implements ILinkifier2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the cache for a link and determine if we need to show or hide tooltip
|
// Check the cache for a link and determine if we need to show or hide tooltip
|
||||||
let foundLink = false;
|
|
||||||
let mouseOver = false;
|
let mouseOver = false;
|
||||||
for (let i = 0; i < this._linkCache.length; i++) {
|
for (let i = 0; i < this._linkCache.length; i++) {
|
||||||
const cachedLink = this._linkCache[i].link;
|
const cachedLink = this._linkCache[i].link;
|
||||||
const isInPosition = this._linkAtPosition(cachedLink, position);
|
const isInPosition = this._linkAtPosition(cachedLink, position);
|
||||||
|
|
||||||
// Check if the mouse position contains a link
|
// Check if we need to hide the tooltip
|
||||||
// Also check if it isn't the current line
|
if (!isInPosition && this._linkCache[i].mouseOver) {
|
||||||
if (isInPosition && !this._linkCache[i].mouseOver && position.y < this._bufferService.buffer.y) {
|
|
||||||
// Show the tooltip
|
|
||||||
this._showTooltip(this._element, this._linkCache[i].link, event);
|
|
||||||
this._linkCache[i].mouseOver = true;
|
|
||||||
foundLink = true;
|
|
||||||
this._mouseOverLink = true;
|
|
||||||
} else if (!isInPosition && this._linkCache[i].mouseOver) {
|
|
||||||
// Hide the tooltip
|
// Hide the tooltip
|
||||||
this._hideTooltip(this._element, this._linkCache[i].link, event);
|
this._hideTooltip(this._element, this._linkCache[i].link, event);
|
||||||
this._linkCache[i].mouseOver = false;
|
this._linkCache[i].mouseOver = false;
|
||||||
@@ -94,12 +83,9 @@ export class Linkifier2 implements ILinkifier2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundLink) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mouseOver) {
|
if (!mouseOver) {
|
||||||
this._mouseOverLink = false;
|
this._mouseOverLink = false;
|
||||||
|
this._linkCache = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// The is no link in the cache, so ask for one
|
// The is no link in the cache, so ask for one
|
||||||
|
|||||||
Reference in New Issue
Block a user