Skip to content

Commit

Permalink
Fixed: #5978 support theming-webview-content
Browse files Browse the repository at this point in the history
Signed-off-by: MiaoWoo <admin@yumc.pw>
  • Loading branch information
502647092 committed Aug 19, 2019
1 parent 2d4c845 commit 06fcf18
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import * as theia from '@theia/plugin';
import { BackendInitializationFn, PluginAPIFactory, Plugin, emptyPlugin } from '@theia/plugin-ext';
import { ThemeService } from '@theia/core/src/browser/theming';

export const VSCODE_DEFAULT_API_VERSION = '1.33.1';

Expand Down Expand Up @@ -55,7 +56,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 = relpaceWebViewContent(html);
this.checkIsDisposed();
if (this._html !== newHtml) {
this._html = newHtml;
Expand All @@ -68,7 +69,7 @@ export const doInitialization: BackendInitializationFn = (apiFactory: PluginAPIF
const originalPostMessage = panel.webview.postMessage;
panel.webview.postMessage = (message: any): PromiseLike<boolean> => {
const decoded = JSON.stringify(message);
const newMessage = decoded.replace(new RegExp('vscode-resource:/', 'g'), 'webview/');
const newMessage = relpaceWebViewContent(decoded);
return originalPostMessage.call(panel.webview, JSON.parse(newMessage));
};

Expand Down Expand Up @@ -101,6 +102,10 @@ export const doInitialization: BackendInitializationFn = (apiFactory: PluginAPIF
}
};

function relpaceWebViewContent(html: string): string {
return html.replace(new RegExp('vscode-resource:/', 'g'), 'webview/').replace(/<body>/, `<body class="vscode-${ThemeService.get().getCurrentTheme().id}">`);
}

function overrideInternalLoad(): void {
const module = require('module');
const vscodeModuleName = 'vscode';
Expand Down

0 comments on commit 06fcf18

Please sign in to comment.