From 10dbb8ab7b5089c46f3fc7ddaa2cd19117bf0390 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Fri, 27 Sep 2019 09:05:34 +0200 Subject: [PATCH] revert "Remove leading slash of webview route ..." partially reverting changes from https://github.com/eclipse-theia/theia/pull/5619 which break "html base href" logic in webview for instance in the python extension for vscode. Signed-off-by: Alex Tugarev --- packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts | 4 ++-- .../src/main/browser/webview/theme-rules-service.ts | 2 +- packages/plugin-ext/src/plugin/webviews.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts b/packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts index 4a049bce4de63..97cb8684b9be1 100644 --- a/packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts +++ b/packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts @@ -61,7 +61,7 @@ export const doInitialization: BackendInitializationFn = (apiFactory: PluginAPIF // redefine property Object.defineProperty(panel.webview, 'html', { set: function (html: string): void { - const newHtml = html.replace(new RegExp('vscode-resource:/', 'g'), 'webview/'); + const newHtml = html.replace(new RegExp('vscode-resource:/', 'g'), '/webview/'); this.checkIsDisposed(); if (this._html !== newHtml) { this._html = newHtml; @@ -74,7 +74,7 @@ export const doInitialization: BackendInitializationFn = (apiFactory: PluginAPIF const originalPostMessage = panel.webview.postMessage; panel.webview.postMessage = (message: any): PromiseLike => { const decoded = JSON.stringify(message); - const newMessage = decoded.replace(new RegExp('vscode-resource:/', 'g'), 'webview/'); + const newMessage = decoded.replace(new RegExp('vscode-resource:/', 'g'), '/webview/'); return originalPostMessage.call(panel.webview, JSON.parse(newMessage)); }; diff --git a/packages/plugin-ext/src/main/browser/webview/theme-rules-service.ts b/packages/plugin-ext/src/main/browser/webview/theme-rules-service.ts index de6459c57cb3a..23eba55151663 100644 --- a/packages/plugin-ext/src/main/browser/webview/theme-rules-service.ts +++ b/packages/plugin-ext/src/main/browser/webview/theme-rules-service.ts @@ -135,7 +135,7 @@ export class ThemeRulesService { path = this.isDark() ? value.dark : value.light; } if (path.startsWith('/')) { - path = `webview${path}`; + path = `/webview${path}`; } cssRules.push(`.webview-icon.${key}-file-icon::before { background-image: url(${path}); }`); }); diff --git a/packages/plugin-ext/src/plugin/webviews.ts b/packages/plugin-ext/src/plugin/webviews.ts index 0afe3cb561aec..bef85108ebbea 100644 --- a/packages/plugin-ext/src/plugin/webviews.ts +++ b/packages/plugin-ext/src/plugin/webviews.ts @@ -150,7 +150,7 @@ export class WebviewImpl implements theia.Webview { this.checkIsDisposed(); // replace theia-resource: content in the given message const decoded = JSON.stringify(message); - let newMessage = decoded.replace(new RegExp('theia-resource:/', 'g'), 'webview/'); + let newMessage = decoded.replace(new RegExp('theia-resource:/', 'g'), '/webview/'); if (this._options && this._options.localResourceRoots) { newMessage = this.filterLocalRoots(newMessage, this._options.localResourceRoots); } @@ -191,7 +191,7 @@ export class WebviewImpl implements theia.Webview { } set html(html: string) { - let newHtml = html.replace(new RegExp('theia-resource:/', 'g'), 'webview/'); + let newHtml = html.replace(new RegExp('theia-resource:/', 'g'), '/webview/'); if (this._options && this._options.localResourceRoots) { newHtml = this.filterLocalRoots(newHtml, this._options.localResourceRoots); }