提交 68afee90 编写于 作者: M Matt Bierner

Allow updating webview settings after creation

Fixes #51733
上级 612806b8
......@@ -34,14 +34,14 @@ export class MarkdownPreview {
private isScrolling = false;
private _disposed: boolean = false;
public static async revive(
webview: vscode.WebviewPanel,
state: any,
contentProvider: MarkdownContentProvider,
previewConfigurations: MarkdownPreviewConfigurationManager,
logger: Logger,
topmostLineMonitor: MarkdownFileTopmostLineMonitor
topmostLineMonitor: MarkdownFileTopmostLineMonitor,
contributions: MarkdownContributions,
): Promise<MarkdownPreview> {
const resource = vscode.Uri.parse(state.resource);
const locked = state.locked;
......@@ -56,6 +56,12 @@ export class MarkdownPreview {
logger,
topmostLineMonitor);
preview.editor.webview.options = {
enableScripts: true,
enableCommandUris: true,
localResourceRoots: MarkdownPreview.getLocalResourceRoots(resource, contributions)
};
if (!isNaN(line)) {
preview.line = line;
}
......
......@@ -89,7 +89,8 @@ export class MarkdownPreviewManager implements vscode.WebviewPanelSerializer {
this._contentProvider,
this._previewConfigurations,
this._logger,
this._topmostLineMonitor);
this._topmostLineMonitor,
this._contributions);
this.registerPreview(preview);
}
......
......@@ -5286,7 +5286,7 @@ declare module 'vscode' {
/**
* Content settings for the webview.
*/
readonly options: WebviewOptions;
options: WebviewOptions;
/**
* Contents of the webview.
......
......@@ -19,6 +19,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { extHostNamedCustomer } from './extHostCustomers';
import * as vscode from 'vscode';
@extHostNamedCustomer(MainContext.MainThreadWebviews)
export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviver {
......@@ -105,6 +106,14 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
webview.html = value;
}
$setOptions(handle: WebviewPanelHandle, options: vscode.WebviewOptions): void {
const webview = this.getWebview(handle);
webview.setOptions({
...options,
localResourceRoots: Array.isArray(options.localResourceRoots) ? options.localResourceRoots.map(URI.revive) : undefined
});
}
$reveal(handle: WebviewPanelHandle, viewColumn: EditorViewColumn | null, preserveFocus: boolean): void {
const webview = this.getWebview(handle);
if (webview.isDisposed()) {
......
......@@ -428,6 +428,7 @@ export interface MainThreadWebviewsShape extends IDisposable {
$reveal(handle: WebviewPanelHandle, viewColumn: EditorViewColumn | null, preserveFocus: boolean): void;
$setTitle(handle: WebviewPanelHandle, value: string): void;
$setHtml(handle: WebviewPanelHandle, value: string): void;
$setOptions(handle: WebviewPanelHandle, options: vscode.WebviewOptions): void;
$postMessage(handle: WebviewPanelHandle, value: any): Thenable<boolean>;
$registerSerializer(viewType: string): void;
......
......@@ -19,7 +19,7 @@ export class ExtHostWebview implements vscode.Webview {
private _options: vscode.WebviewOptions;
private _isDisposed: boolean = false;
readonly _onMessageEmitter = new Emitter<any>();
public readonly _onMessageEmitter = new Emitter<any>();
public readonly onDidReceiveMessage: Event<any> = this._onMessageEmitter.event;
constructor(
......@@ -32,16 +32,16 @@ export class ExtHostWebview implements vscode.Webview {
this._options = options;
}
dispose() {
public dispose() {
this._onMessageEmitter.dispose();
}
get html(): string {
public get html(): string {
this.assertNotDisposed();
return this._html;
}
set html(value: string) {
public set html(value: string) {
this.assertNotDisposed();
if (this._html !== value) {
this._html = value;
......@@ -49,11 +49,17 @@ export class ExtHostWebview implements vscode.Webview {
}
}
get options(): vscode.WebviewOptions {
public get options(): vscode.WebviewOptions {
this.assertNotDisposed();
return this._options;
}
public set options(newOptions: vscode.WebviewOptions) {
this.assertNotDisposed();
this._proxy.$setOptions(this._handle, newOptions);
this._options = newOptions;
}
public postMessage(message: any): Thenable<boolean> {
this.assertNotDisposed();
return this._proxy.$postMessage(this._handle, message);
......
......@@ -11,7 +11,7 @@ import { EditorInput, EditorModel, IEditorInput, GroupIdentifier } from 'vs/work
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { WebviewEvents, WebviewInputOptions, WebviewReviver } from './webviewEditorService';
import { WebviewElement } from './webviewElement';
import * as vscode from 'vscode';
export class WebviewEditorInput extends EditorInput {
private static handlePool = 0;
......@@ -95,7 +95,7 @@ export class WebviewEditorInput extends EditorInput {
this._onDidChangeLabel.fire();
}
matches(other: IEditorInput): boolean {
public matches(other: IEditorInput): boolean {
return other && other === this;
}
......@@ -136,8 +136,15 @@ export class WebviewEditorInput extends EditorInput {
return this._options;
}
public set options(value: WebviewInputOptions) {
this._options = value;
public setOptions(value: vscode.WebviewOptions) {
this._options = {
...this._options,
...value
};
if (this._webview) {
this._webview.options = this._options;
}
}
public resolve(refresh?: boolean): TPromise<IEditorModel, any> {
......
......@@ -251,6 +251,7 @@ export class WebviewElement {
public set options(value: WebviewOptions) {
this._options = value;
this.reload();
}
public set contents(value: string) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册