From d770ce503a136c8592d8cb30c033ce7027cdfb13 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 19 Apr 2018 15:50:54 -0700 Subject: [PATCH] Make sure we handle webview position updates when an entire editor group moves --- src/vs/vscode.d.ts | 4 +++- .../api/electron-browser/mainThreadWebview.ts | 17 ++++++++++++++++- src/vs/workbench/api/node/extHost.protocol.ts | 2 +- src/vs/workbench/api/node/extHostWebview.ts | 9 ++------- .../webview/electron-browser/webviewEditor.ts | 2 +- .../electron-browser/webviewEditorInput.ts | 2 +- .../electron-browser/webviewEditorService.ts | 6 +----- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index bebfdbb8891..93650ca4d4c 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -4964,8 +4964,10 @@ declare module 'vscode' { * * A webview panel may only show in a single column at a time. If it is already showing, this * method moves it to a new column. + * + * @param viewColumn View column to show the panel in. Shows in the current `viewColumn` if undefined. */ - reveal(viewColumn: ViewColumn): void; + reveal(viewColumn?: ViewColumn): void; /** * Dispose of the webview panel. diff --git a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts index c6411afa704..501549b3bbc 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts @@ -52,6 +52,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv ) { this._proxy = context.getProxy(ExtHostContext.ExtHostWebviews); editorGroupService.onEditorsChanged(this.onEditorsChanged, this, this._toDispose); + editorGroupService.onEditorGroupMoved(this.onEditorGroupMoved, this, this._toDispose); this._toDispose.push(_webviewService.registerReviver(MainThreadWebviews.viewType, this)); @@ -96,7 +97,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv webview.html = value; } - $reveal(handle: WebviewPanelHandle, column: Position): void { + $reveal(handle: WebviewPanelHandle, column: Position | undefined): void { const webview = this.getWebview(handle); this._webviewService.revealWebview(webview, column); } @@ -227,6 +228,20 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv } } + private onEditorGroupMoved(): void { + for (const workbenchEditor of this._editorService.getVisibleEditors()) { + if (!workbenchEditor.input) { + return; + } + + this._webviews.forEach((input, handle) => { + if (workbenchEditor.input.matches(input) && input.position !== workbenchEditor.position) { + input.updatePosition(workbenchEditor.position); + this._proxy.$onDidChangeWebviewPanelViewState(handle, handle === this._activeWebview, workbenchEditor.position); + } + }); + } + } private onDidClickLink(handle: WebviewPanelHandle, link: URI): void { if (!link) { return; diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index a6130803b52..798b71e2207 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -355,7 +355,7 @@ export type WebviewPanelHandle = string; export interface MainThreadWebviewsShape extends IDisposable { $createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, column: EditorPosition, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionFolderPath: string): void; $disposeWebview(handle: WebviewPanelHandle): void; - $reveal(handle: WebviewPanelHandle, column: EditorPosition): void; + $reveal(handle: WebviewPanelHandle, column: EditorPosition | undefined): void; $setTitle(handle: WebviewPanelHandle, value: string): void; $setHtml(handle: WebviewPanelHandle, value: string): void; $postMessage(handle: WebviewPanelHandle, value: any): Thenable; diff --git a/src/vs/workbench/api/node/extHostWebview.ts b/src/vs/workbench/api/node/extHostWebview.ts index 7849ba9ea13..e91157377ab 100644 --- a/src/vs/workbench/api/node/extHostWebview.ts +++ b/src/vs/workbench/api/node/extHostWebview.ts @@ -58,11 +58,6 @@ export class ExtHostWebview implements vscode.Webview { return this._proxy.$postMessage(this._handle, message); } - public reveal(viewColumn: vscode.ViewColumn): void { - this.assertNotDisposed(); - this._proxy.$reveal(this._handle, typeConverters.fromViewColumn(viewColumn)); - } - private assertNotDisposed() { if (this._isDisposed) { throw new Error('Webview is disposed'); @@ -176,9 +171,9 @@ export class ExtHostWebviewPanel implements vscode.WebviewPanel { return this._proxy.$postMessage(this._handle, message); } - public reveal(viewColumn: vscode.ViewColumn): void { + public reveal(viewColumn?: vscode.ViewColumn): void { this.assertNotDisposed(); - this._proxy.$reveal(this._handle, typeConverters.fromViewColumn(viewColumn)); + this._proxy.$reveal(this._handle, viewColumn ? typeConverters.fromViewColumn(viewColumn) : undefined); } private assertNotDisposed() { diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts index 6ff804fc51d..aada9f588dc 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts @@ -148,7 +148,7 @@ export class WebviewEditor extends BaseWebviewEditor { await super.setInput(input, options); await input.resolve(); - await input.onBecameActive(this.position); + await input.updatePosition(this.position); this.updateWebview(input); } diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts index 13bdd34b0a4..516b46d3d5b 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts @@ -224,7 +224,7 @@ export class WebviewEditorInput extends EditorInput { this._currentWebviewHtml = ''; } - public onBecameActive(position: Position): void { + public updatePosition(position: Position): void { this._position = position; } } diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts index 03cf243a74a..1d0f11200ca 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts @@ -100,11 +100,7 @@ export class WebviewEditorService implements IWebviewEditorService { webview: WebviewEditorInput, column: Position | undefined ): void { - if (typeof column === 'undefined') { - column = webview.position; - } - - if (webview.position === column) { + if (typeof column === 'undefined' || webview.position === column) { this._editorService.openEditor(webview, { preserveFocus: false }, column); } else { this._editorGroupService.moveEditor(webview, webview.position, column, { preserveFocus: false });