diff --git a/extensions/markdown-language-features/src/features/preview.ts b/extensions/markdown-language-features/src/features/preview.ts index 31e862bd8a6d71bfe722770df22e1a378f5d5377..2f4993fa13aa13e2dd249fc36944637bc186e80e 100644 --- a/extensions/markdown-language-features/src/features/preview.ts +++ b/extensions/markdown-language-features/src/features/preview.ts @@ -54,13 +54,10 @@ export class MarkdownPreview { contentProvider, previewConfigurations, logger, - topmostLineMonitor); + topmostLineMonitor, + contributions); - preview.editor.webview.options = { - enableScripts: true, - enableCommandUris: true, - localResourceRoots: MarkdownPreview.getLocalResourceRoots(resource, contributions) - }; + preview.editor.webview.options = MarkdownPreview.getWebviewOptions(resource, contributions); if (!isNaN(line)) { preview.line = line; @@ -83,10 +80,8 @@ export class MarkdownPreview { MarkdownPreview.viewType, MarkdownPreview.getPreviewTitle(resource, locked), previewColumn, { - enableScripts: true, - enableCommandUris: true, enableFindWidget: true, - localResourceRoots: MarkdownPreview.getLocalResourceRoots(resource, contributions) + ...MarkdownPreview.getWebviewOptions(resource, contributions) }); return new MarkdownPreview( @@ -96,7 +91,8 @@ export class MarkdownPreview { contentProvider, previewConfigurations, logger, - topmostLineMonitor); + topmostLineMonitor, + contributions); } private constructor( @@ -106,7 +102,8 @@ export class MarkdownPreview { private readonly _contentProvider: MarkdownContentProvider, private readonly _previewConfigurations: MarkdownPreviewConfigurationManager, private readonly _logger: Logger, - topmostLineMonitor: MarkdownFileTopmostLineMonitor + topmostLineMonitor: MarkdownFileTopmostLineMonitor, + private readonly _contributions: MarkdownContributions, ) { this._resource = resource; this._locked = locked; @@ -245,10 +242,6 @@ export class MarkdownPreview { return this.editor.viewColumn; } - public isWebviewOf(webview: vscode.WebviewPanel): boolean { - return this.editor === webview; - } - public matchesResource( otherResource: vscode.Uri, otherPosition: vscode.ViewColumn | undefined, @@ -334,10 +327,22 @@ export class MarkdownPreview { const content = await this._contentProvider.provideTextDocumentContent(document, this._previewConfigurations, this.line, this.state); if (this._resource === resource) { this.editor.title = MarkdownPreview.getPreviewTitle(this._resource, this._locked); + this.editor.webview.options = MarkdownPreview.getWebviewOptions(resource, this._contributions); this.editor.webview.html = content; } } + private static getWebviewOptions( + resource: vscode.Uri, + contributions: MarkdownContributions + ): vscode.WebviewOptions { + return { + enableScripts: true, + enableCommandUris: true, + localResourceRoots: MarkdownPreview.getLocalResourceRoots(resource, contributions) + }; + } + private static getLocalResourceRoots( resource: vscode.Uri, contributions: MarkdownContributions diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts index b0e3b1fd791daab1a942b5f0360d6018853ca5a9..8a2a3f989bca2c786459baa2cd322aec5e06b473 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts @@ -144,7 +144,13 @@ export class WebviewEditorInput extends EditorInput { }; if (this._webview) { - this._webview.options = this._options; + this._webview.options = { + allowScripts: this._options.enableScripts, + allowSvgs: true, + enableWrappedPostMessage: true, + useSameOriginForRoot: false, + localResourceRoots: this._options.localResourceRoots + }; } } diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewElement.ts b/src/vs/workbench/parts/webview/electron-browser/webviewElement.ts index 2bdf18032ae42d17cec2b7576f5a70e6e6ca0e55..163ff3faa75924eb3dca697ce88f9ab617a5912f 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewElement.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewElement.ts @@ -256,7 +256,11 @@ export class WebviewElement extends Disposable { public set options(value: WebviewOptions) { this._options = value; - this.reload(); + this._send('content', { + contents: this._contents, + options: this._options, + state: this._state + }); } public set contents(value: string) {