提交 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 {
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
......
......@@ -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
};
}
}
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册