Skip to content

Commit 5f6089a

Browse files
committed
Use asExternalUri instead
1 parent c680e64 commit 5f6089a

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/helpViewer/panel.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,13 @@ export class HelpPanel {
8080
}
8181

8282
// retrieves the stored webview or creates a new one if the webview was closed
83-
private getWebview(port: number | undefined = 0, preserveFocus: boolean = false, viewColumn: vscode.ViewColumn = vscode.ViewColumn.Two): vscode.Webview {
83+
private getWebview(preserveFocus: boolean = false, viewColumn: vscode.ViewColumn = vscode.ViewColumn.Two): vscode.Webview {
8484
// create webview if necessary
8585
if (!this.panel) {
8686
const webViewOptions: vscode.WebviewOptions & vscode.WebviewPanelOptions = {
8787
enableScripts: true,
8888
enableFindWidget: true,
89-
retainContextWhenHidden: true, // keep scroll position when not focussed
90-
portMapping: port ? [
91-
{
92-
webviewPort: port,
93-
extensionHostPort: port
94-
}
95-
] : undefined
89+
retainContextWhenHidden: true // keep scroll position when not focussed
9690
};
9791
const showOptions = {
9892
viewColumn: viewColumn,
@@ -158,11 +152,10 @@ export class HelpPanel {
158152
helpFile.scrollY = helpFile.scrollY || 0;
159153

160154
// modify html
161-
helpFile = this.pimpMyHelp(helpFile, this.webviewStyleUri, this.webviewScriptUri);
155+
helpFile = await this.pimpMyHelp(helpFile, this.webviewStyleUri, this.webviewScriptUri);
162156

163157
// get or create webview:
164-
const helpUrl = helpFile.url ? new URL(helpFile.url) : undefined;
165-
const webview = this.getWebview(helpUrl ? Number(helpUrl.port) : undefined, preserveFocus, viewColumn);
158+
const webview = this.getWebview(preserveFocus, viewColumn);
166159

167160
// actually show the help page
168161
webview.html = helpFile.html;
@@ -350,7 +343,7 @@ export class HelpPanel {
350343
}
351344

352345
// improves the help display by applying syntax highlighting and adjusting hyperlinks:
353-
private pimpMyHelp(helpFile: HelpFile, styleUri?: vscode.Uri | string, scriptUri?: vscode.Uri | string): HelpFile {
346+
private async pimpMyHelp(helpFile: HelpFile, styleUri?: vscode.Uri | string, scriptUri?: vscode.Uri | string): Promise<HelpFile> {
354347

355348
// get requestpath of helpfile
356349
const relPath = helpFile.requestPath + (helpFile.hash || '');
@@ -367,13 +360,14 @@ export class HelpPanel {
367360
// replace katex js/css urls with http://localhost:<port>/ origin
368361
// and remove others.
369362
const url = new URL(helpFile.url);
363+
const externalUri = (await vscode.env.asExternalUri(vscode.Uri.parse(url.origin))).toString(true);
370364

371365
$('link').each((i, e) => {
372366
const obj = $(e);
373367
const linkUrl = obj.attr('href');
374368
if (linkUrl) {
375369
if (linkUrl.includes('katex')) {
376-
const newUrl = new URL(linkUrl, url.origin);
370+
const newUrl = new URL(linkUrl, externalUri);
377371
obj.attr('href', newUrl.toString());
378372
} else {
379373
obj.remove();
@@ -386,15 +380,15 @@ export class HelpPanel {
386380
const scriptUrl = obj.attr('src');
387381
if (scriptUrl) {
388382
if (scriptUrl.includes('katex')) {
389-
const newUrl = new URL(scriptUrl, url.origin);
383+
const newUrl = new URL(scriptUrl, externalUri);
390384
obj.attr('src', newUrl.toString());
391385
} else {
392386
obj.remove();
393387
}
394388
}
395389
});
396390
}
397-
391+
398392
if (styleUri) {
399393
$('body').append(`\n<link rel="stylesheet" href="${styleUri.toString(true)}"></link>`);
400394
}

0 commit comments

Comments
 (0)