|
3 | 3 | * @license MIT |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { Terminal, ILinkMatcherOptions, ITerminalAddon, IDisposable } from 'xterm'; |
| 6 | +import { Terminal, ILinkMatcherOptions, ITerminalAddon, IDisposable, IViewportRange } from 'xterm'; |
7 | 7 | import { WebLinkProvider } from './WebLinkProvider'; |
8 | 8 |
|
9 | 9 | const protocolClause = '(https?:\\/\\/)'; |
@@ -36,27 +36,34 @@ function handleLink(event: MouseEvent, uri: string): void { |
36 | 36 | } |
37 | 37 | } |
38 | 38 |
|
| 39 | +interface ILinkProviderOptions { |
| 40 | + hover?(event: MouseEvent, text: string, location: IViewportRange): void; |
| 41 | + leave?(event: MouseEvent, text: string): void; |
| 42 | +} |
| 43 | + |
39 | 44 | export class WebLinksAddon implements ITerminalAddon { |
40 | 45 | private _linkMatcherId: number | undefined; |
41 | 46 | private _terminal: Terminal | undefined; |
42 | 47 | private _linkProvider: IDisposable | undefined; |
43 | 48 |
|
44 | 49 | constructor( |
45 | 50 | private _handler: (event: MouseEvent, uri: string) => void = handleLink, |
46 | | - private _options: ILinkMatcherOptions = {}, |
| 51 | + private _options: ILinkMatcherOptions | ILinkProviderOptions = {}, |
47 | 52 | private _useLinkProvider: boolean = false |
48 | 53 | ) { |
49 | | - this._options.matchIndex = 1; |
50 | 54 | } |
51 | 55 |
|
52 | 56 | public activate(terminal: Terminal): void { |
53 | 57 | this._terminal = terminal; |
54 | 58 |
|
55 | 59 | if (this._useLinkProvider && 'registerLinkProvider' in this._terminal) { |
56 | | - this._linkProvider = this._terminal.registerLinkProvider(new WebLinkProvider(this._terminal, strictUrlRegex, this._handler)); |
| 60 | + const options = this._options as ILinkProviderOptions; |
| 61 | + this._linkProvider = this._terminal.registerLinkProvider(new WebLinkProvider(this._terminal, strictUrlRegex, this._handler, options)); |
57 | 62 | } else { |
58 | 63 | // TODO: This should be removed eventually |
59 | | - this._linkMatcherId = (this._terminal as Terminal).registerLinkMatcher(strictUrlRegex, this._handler, this._options); |
| 64 | + const options = this._options as ILinkMatcherOptions; |
| 65 | + options.matchIndex = 1; |
| 66 | + this._linkMatcherId = (this._terminal as Terminal).registerLinkMatcher(strictUrlRegex, this._handler, options); |
60 | 67 | } |
61 | 68 | } |
62 | 69 |
|
|
0 commit comments