Correctly set webview active state on restore

Fixes #145648
This commit is contained in:
Matt Bierner 2022-04-05 16:03:13 -07:00
parent a4ff080324
commit 32acfdde2a
No known key found for this signature in database
GPG key ID: 099C331567E11888
5 changed files with 26 additions and 17 deletions

View file

@ -275,6 +275,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
state,
panelOptions: webviewInput.webview.options,
webviewOptions: webviewInput.webview.contentOptions,
active: webviewInput === this._editorService.activeEditor,
}, editorGroupToColumn(this._editorGroupService, webviewInput.group || 0));
} catch (error) {
onUnexpectedError(error);

View file

@ -866,6 +866,7 @@ export interface ExtHostWebviewPanelsShape {
state: any;
webviewOptions: IWebviewContentOptions;
panelOptions: IWebviewPanelOptions;
active: boolean;
},
position: EditorGroupColumn,
): Promise<void>;

View file

@ -267,7 +267,7 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor
const viewColumn = typeConverters.ViewColumn.to(position);
const webview = this._extHostWebview.createNewWebview(handle, initData.webviewOptions, entry.extension);
const panel = this._extHostWebviewPanels.createNewWebviewPanel(handle, viewType, initData.title, viewColumn, initData.panelOptions, webview);
const panel = this._extHostWebviewPanels.createNewWebviewPanel(handle, viewType, initData.title, viewColumn, initData.panelOptions, webview, true);
const revivedResource = URI.revive(resource);

View file

@ -32,7 +32,7 @@ class ExtHostWebviewPanel extends Disposable implements vscode.WebviewPanel {
#iconPath?: IconPath;
#viewColumn: vscode.ViewColumn | undefined = undefined;
#visible: boolean = true;
#active: boolean = true;
#active: boolean;
#isDisposed: boolean = false;
readonly #onDidDispose = this._register(new Emitter<void>());
@ -44,20 +44,24 @@ class ExtHostWebviewPanel extends Disposable implements vscode.WebviewPanel {
constructor(
handle: extHostProtocol.WebviewHandle,
proxy: extHostProtocol.MainThreadWebviewPanelsShape,
viewType: string,
title: string,
viewColumn: vscode.ViewColumn | undefined,
panelOptions: vscode.WebviewPanelOptions,
webview: ExtHostWebview
webview: ExtHostWebview,
params: {
viewType: string;
title: string;
viewColumn: vscode.ViewColumn | undefined;
panelOptions: vscode.WebviewPanelOptions;
active: boolean;
}
) {
super();
this.#handle = handle;
this.#proxy = proxy;
this.#viewType = viewType;
this.#options = panelOptions;
this.#viewColumn = viewColumn;
this.#title = title;
this.#webview = webview;
this.#viewType = params.viewType;
this.#options = params.panelOptions;
this.#viewColumn = params.viewColumn;
this.#title = params.title;
this.#active = params.active;
}
public override dispose() {
@ -209,7 +213,7 @@ export class ExtHostWebviewPanels implements extHostProtocol.ExtHostWebviewPanel
}, webviewShowOptions);
const webview = this.webviews.createNewWebview(handle, options, extension);
const panel = this.createNewWebviewPanel(handle, viewType, title, viewColumn, options, webview);
const panel = this.createNewWebviewPanel(handle, viewType, title, viewColumn, options, webview, true);
return panel;
}
@ -283,6 +287,7 @@ export class ExtHostWebviewPanels implements extHostProtocol.ExtHostWebviewPanel
state: any;
webviewOptions: extHostProtocol.IWebviewContentOptions;
panelOptions: extHostProtocol.IWebviewPanelOptions;
active: boolean;
},
position: EditorGroupColumn
): Promise<void> {
@ -293,12 +298,12 @@ export class ExtHostWebviewPanels implements extHostProtocol.ExtHostWebviewPanel
const { serializer, extension } = entry;
const webview = this.webviews.createNewWebview(webviewHandle, initData.webviewOptions, extension);
const revivedPanel = this.createNewWebviewPanel(webviewHandle, viewType, initData.title, position, initData.panelOptions, webview);
const revivedPanel = this.createNewWebviewPanel(webviewHandle, viewType, initData.title, position, initData.panelOptions, webview, initData.active);
await serializer.deserializeWebviewPanel(revivedPanel, initData.state);
}
public createNewWebviewPanel(webviewHandle: string, viewType: string, title: string, position: vscode.ViewColumn, options: extHostProtocol.IWebviewPanelOptions, webview: ExtHostWebview) {
const panel = new ExtHostWebviewPanel(webviewHandle, this._proxy, viewType, title, position, options, webview);
public createNewWebviewPanel(webviewHandle: string, viewType: string, title: string, position: vscode.ViewColumn, options: extHostProtocol.IWebviewPanelOptions, webview: ExtHostWebview, active: boolean) {
const panel = new ExtHostWebviewPanel(webviewHandle, this._proxy, webview, { viewType, title, viewColumn: position, panelOptions: options, active });
this._webviewPanels.set(webviewHandle, panel);
return panel;
}

View file

@ -55,7 +55,8 @@ suite('ExtHostWebview', () => {
title: 'title',
state: {},
panelOptions: {},
webviewOptions: {}
webviewOptions: {},
active: true,
}, 0 as EditorGroupColumn);
assert.strictEqual(lastInvokedDeserializer, serializerA);
@ -71,7 +72,8 @@ suite('ExtHostWebview', () => {
title: 'title',
state: {},
panelOptions: {},
webviewOptions: {}
webviewOptions: {},
active: true,
}, 0 as EditorGroupColumn);
assert.strictEqual(lastInvokedDeserializer, serializerB);
});