Skip to content

Commit

Permalink
Added special handling of link over tooltip for DOM renderer
Browse files Browse the repository at this point in the history
Fixes #50128
  • Loading branch information
alexr00 committed Sep 20, 2018
1 parent abee50e commit 78d90f0
Showing 1 changed file with 30 additions and 5 deletions.
Expand Up @@ -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 = '\\/';
Expand Down Expand Up @@ -62,7 +64,7 @@ export class TerminalLinkHandler {
private _mouseMoveDisposable: IDisposable;
private _widgetManager: TerminalWidgetManager;
private _initialCwd: string;

private _configHelper: TerminalConfigHelper;
private _localLinkPattern: RegExp;

constructor(
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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)
});
Expand All @@ -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
Expand Down

0 comments on commit 78d90f0

Please sign in to comment.