提交 9bf3f954 编写于 作者: J Jon Bockhorst

Fix terminal Follow Link handlers

上级 858457d2
......@@ -669,7 +669,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._refreshSelectionContextKey();
}));
const widgetManager = new TerminalWidgetManager(this._wrapperElement, this._openerService);
const widgetManager = new TerminalWidgetManager(this._wrapperElement);
this._widgetManager = widgetManager;
this._processManager.onProcessReady(() => this._linkHandler?.setWidgetManager(widgetManager));
......
......@@ -72,7 +72,7 @@ export class TerminalLinkHandler {
private _processCwd: string | undefined;
private _gitDiffPreImagePattern: RegExp;
private _gitDiffPostImagePattern: RegExp;
private readonly _tooltipCallback: (event: MouseEvent, uri: string, location: IViewportRange) => boolean | void;
private readonly _tooltipCallback: (event: MouseEvent, uri: string, location: IViewportRange, linkHandler: (url: string) => void) => boolean | void;
private readonly _leaveCallback: () => void;
constructor(
......@@ -90,7 +90,7 @@ export class TerminalLinkHandler {
// Matches '+++ b/src/file1', capturing 'src/file1' in group 1
this._gitDiffPostImagePattern = /^\+\+\+ b\/(\S*)/;
this._tooltipCallback = (e: MouseEvent, uri: string, location: IViewportRange) => {
this._tooltipCallback = (e: MouseEvent, uri: string, location: IViewportRange, linkHandler: (url: string) => void) => {
if (!this._widgetManager) {
return;
}
......@@ -117,7 +117,7 @@ export class TerminalLinkHandler {
const leftPosition = location.start.x * (charWidth! + (font.letterSpacing / window.devicePixelRatio));
const bottomPosition = offsetRow * (Math.ceil(charHeight! * window.devicePixelRatio) * font.lineHeight) / window.devicePixelRatio;
this._widgetManager.showMessage(leftPosition, bottomPosition, this._getLinkHoverString(uri), verticalAlignment);
this._widgetManager.showMessage(leftPosition, bottomPosition, this._getLinkHoverString(uri), verticalAlignment, linkHandler);
} else {
const target = (e.target as HTMLElement);
const colWidth = target.offsetWidth / this._xterm.cols;
......@@ -125,7 +125,7 @@ export class TerminalLinkHandler {
const leftPosition = location.start.x * colWidth;
const bottomPosition = offsetRow * rowHeight;
this._widgetManager.showMessage(leftPosition, bottomPosition, this._getLinkHoverString(uri), verticalAlignment);
this._widgetManager.showMessage(leftPosition, bottomPosition, this._getLinkHoverString(uri), verticalAlignment, linkHandler);
}
};
this._leaveCallback = () => {
......@@ -152,9 +152,12 @@ export class TerminalLinkHandler {
}
public registerCustomLinkHandler(regex: RegExp, handler: (uri: string) => void, matchIndex?: number, validationCallback?: XtermLinkMatcherValidationCallback): number {
const tooltipCallback = (event: MouseEvent, uri: string, location: IViewportRange) => {
this._tooltipCallback(event, uri, location, handler);
};
const options: ILinkMatcherOptions = {
matchIndex,
tooltipCallback: this._tooltipCallback,
tooltipCallback,
leaveCallback: this._leaveCallback,
willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e),
priority: CUSTOM_LINK_PRIORITY
......@@ -173,9 +176,12 @@ export class TerminalLinkHandler {
const wrappedHandler = this._wrapLinkHandler(uri => {
this._handleHypertextLink(uri);
});
const tooltipCallback = (event: MouseEvent, uri: string, location: IViewportRange) => {
this._tooltipCallback(event, uri, location, this._handleHypertextLink.bind(this));
};
this._xterm.loadAddon(new WebLinksAddon(wrappedHandler, {
validationCallback: (uri: string, callback: (isValid: boolean) => void) => this._validateWebLink(uri, callback),
tooltipCallback: this._tooltipCallback,
tooltipCallback,
leaveCallback: this._leaveCallback,
willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e)
}));
......@@ -186,9 +192,12 @@ export class TerminalLinkHandler {
const wrappedHandler = this._wrapLinkHandler(url => {
this._handleLocalLink(url);
});
const tooltipCallback = (event: MouseEvent, uri: string, location: IViewportRange) => {
this._tooltipCallback(event, uri, location, this._handleLocalLink.bind(this));
};
this._xterm.registerLinkMatcher(this._localLinkRegex, wrappedHandler, {
validationCallback: (uri: string, callback: (isValid: boolean) => void) => this._validateLocalLink(uri, callback),
tooltipCallback: this._tooltipCallback,
tooltipCallback,
leaveCallback: this._leaveCallback,
willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e),
priority: LOCAL_LINK_PRIORITY
......@@ -199,10 +208,13 @@ export class TerminalLinkHandler {
const wrappedHandler = this._wrapLinkHandler(url => {
this._handleLocalLink(url);
});
const tooltipCallback = (event: MouseEvent, uri: string, location: IViewportRange) => {
this._tooltipCallback(event, uri, location, this._handleLocalLink.bind(this));
};
const options = {
matchIndex: 1,
validationCallback: (uri: string, callback: (isValid: boolean) => void) => this._validateLocalLink(uri, callback),
tooltipCallback: this._tooltipCallback,
tooltipCallback,
leaveCallback: this._leaveCallback,
willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e),
priority: LOCAL_LINK_PRIORITY
......
......@@ -6,8 +6,6 @@
import { IDisposable, dispose, DisposableStore } from 'vs/base/common/lifecycle';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { renderMarkdown } from 'vs/base/browser/markdownRenderer';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { URI } from 'vs/base/common/uri';
export enum WidgetVerticalAlignment {
Bottom,
......@@ -25,7 +23,6 @@ export class TerminalWidgetManager implements IDisposable {
constructor(
terminalWrapper: HTMLElement,
private readonly _openerService: IOpenerService
) {
this._container = document.createElement('div');
this._container.classList.add('terminal-widget-overlay');
......@@ -53,13 +50,13 @@ export class TerminalWidgetManager implements IDisposable {
mutationObserver.observe(this._xtermViewport, { attributes: true, attributeFilter: ['style'] });
}
public showMessage(left: number, y: number, text: IMarkdownString, verticalAlignment: WidgetVerticalAlignment = WidgetVerticalAlignment.Bottom): void {
public showMessage(left: number, y: number, text: IMarkdownString, verticalAlignment: WidgetVerticalAlignment = WidgetVerticalAlignment.Bottom, linkHandler: (url: string) => void): void {
if (!this._container) {
return;
}
dispose(this._messageWidget);
this._messageListeners.clear();
this._messageWidget = new MessageWidget(this._container, left, y, text, verticalAlignment, this._openerService);
this._messageWidget = new MessageWidget(this._container, left, y, text, verticalAlignment, linkHandler);
}
public closeMessage(): void {
......@@ -110,11 +107,11 @@ class MessageWidget {
private _y: number,
private _text: IMarkdownString,
private _verticalAlignment: WidgetVerticalAlignment,
private readonly _openerService: IOpenerService
private _linkHandler: (url: string) => void
) {
this._domNode = renderMarkdown(this._text, {
actionHandler: {
callback: this._handleLinkClicked.bind(this),
callback: this._linkHandler,
disposeables: this._messageListeners
}
});
......@@ -149,8 +146,4 @@ class MessageWidget {
this._messageListeners.dispose();
}
private _handleLinkClicked(content: string) {
this._openerService.open(URI.parse(content));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册