From 32acfdde2a098ddf0cdb71252920318ca7cd16e5 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 5 Apr 2022 16:03:13 -0700 Subject: [PATCH] Correctly set webview active state on restore Fixes #145648 --- .../api/browser/mainThreadWebviewPanels.ts | 1 + .../workbench/api/common/extHost.protocol.ts | 1 + .../api/common/extHostCustomEditors.ts | 2 +- .../api/common/extHostWebviewPanels.ts | 33 +++++++++++-------- .../api/test/browser/extHostWebview.test.ts | 6 ++-- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts b/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts index 3ca501b079b..c357cca23d2 100644 --- a/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts +++ b/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts @@ -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); diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 86d8dde204b..307d7340923 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -866,6 +866,7 @@ export interface ExtHostWebviewPanelsShape { state: any; webviewOptions: IWebviewContentOptions; panelOptions: IWebviewPanelOptions; + active: boolean; }, position: EditorGroupColumn, ): Promise; diff --git a/src/vs/workbench/api/common/extHostCustomEditors.ts b/src/vs/workbench/api/common/extHostCustomEditors.ts index 7c9e25f6126..24ee34186c0 100644 --- a/src/vs/workbench/api/common/extHostCustomEditors.ts +++ b/src/vs/workbench/api/common/extHostCustomEditors.ts @@ -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); diff --git a/src/vs/workbench/api/common/extHostWebviewPanels.ts b/src/vs/workbench/api/common/extHostWebviewPanels.ts index 2f2e575ed76..189d350428b 100644 --- a/src/vs/workbench/api/common/extHostWebviewPanels.ts +++ b/src/vs/workbench/api/common/extHostWebviewPanels.ts @@ -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()); @@ -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 { @@ -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; } diff --git a/src/vs/workbench/api/test/browser/extHostWebview.test.ts b/src/vs/workbench/api/test/browser/extHostWebview.test.ts index cce4f74d246..50327ab707d 100644 --- a/src/vs/workbench/api/test/browser/extHostWebview.test.ts +++ b/src/vs/workbench/api/test/browser/extHostWebview.test.ts @@ -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); });