From a685ac69d57725d300af72aba95c7a913a03acad Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 6 May 2020 04:08:46 -0700 Subject: [PATCH] Update protocol links with new model --- .../browser/links/terminalLinkManager.ts | 6 ++-- .../links/terminalProtocolLinkProvider.ts | 32 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts index 8cf791e5b2e..fa8cfed1fb7 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts @@ -297,9 +297,9 @@ export class TerminalLinkManager extends DisposableStore { public registerLinkProvider(): void { // Protocol links - // const wrappedActivateCallback = this._wrapLinkHandler((_, link) => this._handleProtocolLink(link)); - // const protocolProvider = this._instantiationService.createInstance(TerminalProtocolLinkProvider, this._xterm, wrappedActivateCallback, this._tooltipCallback2.bind(this)); - // this._linkProviders.push(this._xterm.registerLinkProvider(protocolProvider)); + const wrappedActivateCallback = this._wrapLinkHandler((_, link) => this._handleProtocolLink(link)); + const protocolProvider = this._instantiationService.createInstance(TerminalProtocolLinkProvider, this._xterm, wrappedActivateCallback, this._tooltipCallback2.bind(this)); + this._linkProviders.push(this._xterm.registerLinkProvider(protocolProvider)); // // Validated local links // if (this._configurationService.getValue(TERMINAL_CONFIG_SECTION).enableFileLinks) { diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts index bec87ee04d7..6179c58e7bf 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts @@ -3,14 +3,15 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Terminal, IViewportRange, ILinkProvider, IBufferCellPosition, ILink, IBufferLine } from 'xterm'; +import { Terminal, IViewportRange, IBufferLine } from 'xterm'; import { ILinkComputerTarget, LinkComputer } from 'vs/editor/common/modes/linkComputer'; -import { getXtermLineContent, convertLinkRangeToBuffer, positionIsInRange } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkHelpers'; +import { getXtermLineContent, convertLinkRangeToBuffer } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkHelpers'; import { TerminalLink, OPEN_FILE_LABEL } from 'vs/workbench/contrib/terminal/browser/links/terminalLink'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { URI } from 'vs/base/common/uri'; +import { TerminalBaseLinkProvider } from 'vs/workbench/contrib/terminal/browser/links/terminalBaseLinkProvider'; -export class TerminalProtocolLinkProvider implements ILinkProvider { +export class TerminalProtocolLinkProvider extends TerminalBaseLinkProvider { private _linkComputerTarget: ILinkComputerTarget | undefined; constructor( @@ -19,10 +20,11 @@ export class TerminalProtocolLinkProvider implements ILinkProvider { private readonly _tooltipCallback: (link: TerminalLink, viewportRange: IViewportRange, modifierDownCallback?: () => void, modifierUpCallback?: () => void) => void, @IInstantiationService private readonly _instantiationService: IInstantiationService ) { + super(); } - public provideLink(position: IBufferCellPosition, callback: (link: ILink | undefined) => void): void { - let startLine = position.y - 1; + protected _provideLinks(y: number): TerminalLink[] { + let startLine = y - 1; let endLine = startLine; const lines: IBufferLine[] = [ @@ -42,24 +44,16 @@ export class TerminalProtocolLinkProvider implements ILinkProvider { this._linkComputerTarget = new TerminalLinkAdapter(this._xterm, startLine, endLine); const links = LinkComputer.computeLinks(this._linkComputerTarget); - let found = false; - links.forEach(link => { + return links.map(link => { const range = convertLinkRangeToBuffer(lines, this._xterm.cols, link.range, startLine); // Check if the link if within the mouse position - if (positionIsInRange(position, range)) { - found = true; - const uri = link.url - ? (typeof link.url === 'string' ? URI.parse(link.url) : link.url) - : undefined; - const label = (uri?.scheme === 'file') ? OPEN_FILE_LABEL : undefined; - callback(this._instantiationService.createInstance(TerminalLink, range, link.url?.toString() || '', this._xterm.buffer.active.viewportY, this._activateCallback, this._tooltipCallback, true, label)); - } + const uri = link.url + ? (typeof link.url === 'string' ? URI.parse(link.url) : link.url) + : undefined; + const label = (uri?.scheme === 'file') ? OPEN_FILE_LABEL : undefined; + return this._instantiationService.createInstance(TerminalLink, range, link.url?.toString() || '', this._xterm.buffer.active.viewportY, this._activateCallback, this._tooltipCallback, true, label); }); - - if (!found) { - callback(undefined); - } } }