提交 78f410ce 编写于 作者: M Matt Bierner

Make sure we correctly update local resource roots when switching previewed markdown file

Fixes #49859
上级 5aff9aa7
...@@ -54,13 +54,10 @@ export class MarkdownPreview { ...@@ -54,13 +54,10 @@ export class MarkdownPreview {
contentProvider, contentProvider,
previewConfigurations, previewConfigurations,
logger, logger,
topmostLineMonitor); topmostLineMonitor,
contributions);
preview.editor.webview.options = { preview.editor.webview.options = MarkdownPreview.getWebviewOptions(resource, contributions);
enableScripts: true,
enableCommandUris: true,
localResourceRoots: MarkdownPreview.getLocalResourceRoots(resource, contributions)
};
if (!isNaN(line)) { if (!isNaN(line)) {
preview.line = line; preview.line = line;
...@@ -83,10 +80,8 @@ export class MarkdownPreview { ...@@ -83,10 +80,8 @@ export class MarkdownPreview {
MarkdownPreview.viewType, MarkdownPreview.viewType,
MarkdownPreview.getPreviewTitle(resource, locked), MarkdownPreview.getPreviewTitle(resource, locked),
previewColumn, { previewColumn, {
enableScripts: true,
enableCommandUris: true,
enableFindWidget: true, enableFindWidget: true,
localResourceRoots: MarkdownPreview.getLocalResourceRoots(resource, contributions) ...MarkdownPreview.getWebviewOptions(resource, contributions)
}); });
return new MarkdownPreview( return new MarkdownPreview(
...@@ -96,7 +91,8 @@ export class MarkdownPreview { ...@@ -96,7 +91,8 @@ export class MarkdownPreview {
contentProvider, contentProvider,
previewConfigurations, previewConfigurations,
logger, logger,
topmostLineMonitor); topmostLineMonitor,
contributions);
} }
private constructor( private constructor(
...@@ -106,7 +102,8 @@ export class MarkdownPreview { ...@@ -106,7 +102,8 @@ export class MarkdownPreview {
private readonly _contentProvider: MarkdownContentProvider, private readonly _contentProvider: MarkdownContentProvider,
private readonly _previewConfigurations: MarkdownPreviewConfigurationManager, private readonly _previewConfigurations: MarkdownPreviewConfigurationManager,
private readonly _logger: Logger, private readonly _logger: Logger,
topmostLineMonitor: MarkdownFileTopmostLineMonitor topmostLineMonitor: MarkdownFileTopmostLineMonitor,
private readonly _contributions: MarkdownContributions,
) { ) {
this._resource = resource; this._resource = resource;
this._locked = locked; this._locked = locked;
...@@ -245,10 +242,6 @@ export class MarkdownPreview { ...@@ -245,10 +242,6 @@ export class MarkdownPreview {
return this.editor.viewColumn; return this.editor.viewColumn;
} }
public isWebviewOf(webview: vscode.WebviewPanel): boolean {
return this.editor === webview;
}
public matchesResource( public matchesResource(
otherResource: vscode.Uri, otherResource: vscode.Uri,
otherPosition: vscode.ViewColumn | undefined, otherPosition: vscode.ViewColumn | undefined,
...@@ -334,10 +327,22 @@ export class MarkdownPreview { ...@@ -334,10 +327,22 @@ export class MarkdownPreview {
const content = await this._contentProvider.provideTextDocumentContent(document, this._previewConfigurations, this.line, this.state); const content = await this._contentProvider.provideTextDocumentContent(document, this._previewConfigurations, this.line, this.state);
if (this._resource === resource) { if (this._resource === resource) {
this.editor.title = MarkdownPreview.getPreviewTitle(this._resource, this._locked); this.editor.title = MarkdownPreview.getPreviewTitle(this._resource, this._locked);
this.editor.webview.options = MarkdownPreview.getWebviewOptions(resource, this._contributions);
this.editor.webview.html = content; 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( private static getLocalResourceRoots(
resource: vscode.Uri, resource: vscode.Uri,
contributions: MarkdownContributions contributions: MarkdownContributions
......
...@@ -144,7 +144,13 @@ export class WebviewEditorInput extends EditorInput { ...@@ -144,7 +144,13 @@ export class WebviewEditorInput extends EditorInput {
}; };
if (this._webview) { 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
};
} }
} }
......
...@@ -256,7 +256,11 @@ export class WebviewElement extends Disposable { ...@@ -256,7 +256,11 @@ export class WebviewElement extends Disposable {
public set options(value: WebviewOptions) { public set options(value: WebviewOptions) {
this._options = value; this._options = value;
this.reload(); this._send('content', {
contents: this._contents,
options: this._options,
state: this._state
});
} }
public set contents(value: string) { public set contents(value: string) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册