From 78d90f038b29757260e6773e477e98006417bf57 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 20 Sep 2018 11:07:14 -0700 Subject: [PATCH] Added special handling of link over tooltip for DOM renderer Fixes #50128 --- .../electron-browser/terminalLinkHandler.ts | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalLinkHandler.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalLinkHandler.ts index 9186939137fa1..23b657b031f8f 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalLinkHandler.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalLinkHandler.ts @@ -16,6 +16,8 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { ITerminalService } from 'vs/workbench/parts/terminal/common/terminal'; import { ITextEditorSelection } from 'vs/platform/editor/common/editor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { TerminalConfigHelper } from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper'; const pathPrefix = '(\\.\\.?|\\~)'; const pathSeparatorClause = '\\/'; @@ -62,7 +64,7 @@ export class TerminalLinkHandler { private _mouseMoveDisposable: IDisposable; private _widgetManager: TerminalWidgetManager; private _initialCwd: string; - + private _configHelper: TerminalConfigHelper; private _localLinkPattern: RegExp; constructor( @@ -71,13 +73,15 @@ export class TerminalLinkHandler { @IOpenerService private readonly _openerService: IOpenerService, @IEditorService private readonly _editorService: IEditorService, @IConfigurationService private readonly _configurationService: IConfigurationService, - @ITerminalService private readonly _terminalService: ITerminalService + @ITerminalService private readonly _terminalService: ITerminalService, + @IInstantiationService instantiationService: IInstantiationService, ) { const baseLocalLinkClause = _platform === platform.Platform.Windows ? winLocalLinkClause : unixLocalLinkClause; // Append line and column number regex this._localLinkPattern = new RegExp(`${baseLocalLinkClause}(${lineAndColumnClause})`); this.registerWebLinkHandler(); this.registerLocalLinkHandler(); + this._configHelper = instantiationService.createInstance(TerminalConfigHelper); } public setWidgetManager(widgetManager: TerminalWidgetManager): void { @@ -92,7 +96,14 @@ export class TerminalLinkHandler { return this._xterm.registerLinkMatcher(regex, this._wrapLinkHandler(handler), { matchIndex, validationCallback: (uri: string, callback: (isValid: boolean) => void) => validationCallback(uri, callback), - tooltipCallback: (e: MouseEvent) => this._widgetManager.showMessage(e.offsetX, e.offsetY, this._getLinkHoverString()), + tooltipCallback: (e: MouseEvent) => { + if (this._configHelper.config.rendererType === 'dom') { + const target = (e.target as HTMLElement); + this._widgetManager.showMessage(target.offsetLeft, target.offsetTop, this._getLinkHoverString()); + } else { + this._widgetManager.showMessage(e.offsetX, e.offsetY, this._getLinkHoverString()); + } + }, leaveCallback: () => this._widgetManager.closeMessage(), willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e), priority: CUSTOM_LINK_PRIORITY @@ -105,7 +116,14 @@ export class TerminalLinkHandler { }); this._xterm.webLinksInit(wrappedHandler, { validationCallback: (uri: string, callback: (isValid: boolean) => void) => this._validateWebLink(uri, callback), - tooltipCallback: (e: MouseEvent) => this._widgetManager.showMessage(e.offsetX, e.offsetY, this._getLinkHoverString()), + tooltipCallback: (e: MouseEvent) => { + if (this._configHelper.config.rendererType === 'dom') { + const target = (e.target as HTMLElement); + this._widgetManager.showMessage(target.offsetLeft, target.offsetTop, this._getLinkHoverString()); + } else { + this._widgetManager.showMessage(e.offsetX, e.offsetY, this._getLinkHoverString()); + } + }, leaveCallback: () => this._widgetManager.closeMessage(), willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e) }); @@ -117,7 +135,14 @@ export class TerminalLinkHandler { }); this._xterm.registerLinkMatcher(this._localLinkRegex, wrappedHandler, { validationCallback: (uri: string, callback: (isValid: boolean) => void) => this._validateLocalLink(uri, callback), - tooltipCallback: (e: MouseEvent) => this._widgetManager.showMessage(e.offsetX, e.offsetY, this._getLinkHoverString()), + tooltipCallback: (e: MouseEvent) => { + if (this._configHelper.config.rendererType === 'dom') { + const target = (e.target as HTMLElement); + this._widgetManager.showMessage(target.offsetLeft, target.offsetTop, this._getLinkHoverString()); + } else { + this._widgetManager.showMessage(e.offsetX, e.offsetY, this._getLinkHoverString()); + } + }, leaveCallback: () => this._widgetManager.closeMessage(), willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e), priority: LOCAL_LINK_PRIORITY