Skip to content

Commit

Permalink
Upgrade xterm.js, use new webLinks addon to allow dbl/tpl click on link
Browse files Browse the repository at this point in the history
Fixes #41415
  • Loading branch information
Tyriar committed Feb 23, 2018
1 parent 4b4e5ce commit 3373b92
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"vscode-debugprotocol": "1.26.0",
"vscode-ripgrep": "0.7.1-patch.0.1",
"vscode-textmate": "^3.2.0",
"vscode-xterm": "3.2.0-beta4",
"vscode-xterm": "3.2.0-beta6",
"yauzl": "2.8.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/typings/vscode-xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ declare module 'vscode-xterm' {
*/
findPrevious(term: string): boolean;

webLinksInit(handler?: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): void;
winptyCompatInit(): void;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ export class TerminalInstance implements ITerminalInstance {
protected async _createXterm(): TPromise<void> {
if (!Terminal) {
Terminal = (await import('vscode-xterm')).Terminal;
// Enable search functionality in xterm.js instance
// Enable xterm.js addons
Terminal.applyAddon(require.__$__nodeRequire('vscode-xterm/lib/addons/search/search'));
// Enable the winpty compatibility addon which will simulate wraparound mode
Terminal.applyAddon(require.__$__nodeRequire('vscode-xterm/lib/addons/webLinks/webLinks'));
Terminal.applyAddon(require.__$__nodeRequire('vscode-xterm/lib/addons/winptyCompat/winptyCompat'));
// Localize strings
Terminal.strings.blankLine = nls.localize('terminal.integrated.a11yBlankLine', 'Blank line');
Expand Down Expand Up @@ -312,7 +312,6 @@ export class TerminalInstance implements ITerminalInstance {
return false;
});
this._linkHandler = this._instantiationService.createInstance(TerminalLinkHandler, this._xterm, platform.platform, this._initialCwd);
this._linkHandler.registerLocalLinkHandler();
this._instanceDisposables.push(this._themeService.onThemeChange(theme => this._updateTheme(theme)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,8 @@ export class TerminalLinkHandler {
const baseLocalLinkClause = _platform === platform.Platform.Windows ? winLocalLinkClause : unixLocalLinkClause;
// Append line and column number regex
this._localLinkPattern = new RegExp(`${baseLocalLinkClause}(${lineAndColumnClause})`);

this._xterm.setHypertextLinkHandler(this._wrapLinkHandler(uri => {
this._handleHypertextLink(uri);
}));

this._xterm.setHypertextValidationCallback((uri: string, callback: (isValid: boolean) => void) => {
this._validateWebLink(uri, callback);
});
this.registerWebLinkHandler();
this.registerLocalLinkHandler();
}

public setWidgetManager(widgetManager: TerminalWidgetManager): void {
Expand All @@ -100,12 +94,23 @@ export class TerminalLinkHandler {
});
}

public registerLocalLinkHandler(): number {
public registerWebLinkHandler(): void {
const wrappedHandler = this._wrapLinkHandler(uri => {
this._handleHypertextLink(uri);
});
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()),
leaveCallback: () => this._widgetManager.closeMessage(),
willLinkActivate: (e: MouseEvent) => this._isLinkActivationModifierDown(e)
});
}

public registerLocalLinkHandler(): void {
const wrappedHandler = this._wrapLinkHandler(url => {
this._handleLocalLink(url);
});

return this._xterm.registerLinkMatcher(this._localLinkRegex, wrappedHandler, {
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()),
leaveCallback: () => this._widgetManager.closeMessage(),
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6003,9 +6003,9 @@ vscode-textmate@^3.2.0:
fast-plist "^0.1.2"
oniguruma "^6.0.1"

vscode-xterm@3.2.0-beta4:
version "3.2.0-beta4"
resolved "https://registry.yarnpkg.com/vscode-xterm/-/vscode-xterm-3.2.0-beta4.tgz#fdcabafe1b6f89e5490cc816dcf29f0383147d48"
vscode-xterm@3.2.0-beta6:
version "3.2.0-beta6"
resolved "https://registry.yarnpkg.com/vscode-xterm/-/vscode-xterm-3.2.0-beta6.tgz#17d6f41d741c4f7e60a322b18d7bdceec4dfded0"

vso-node-api@^6.1.2-preview:
version "6.1.2-preview"
Expand Down

0 comments on commit 3373b92

Please sign in to comment.