From 06dd68b4e1b4b3a2135095c4ad65de76cc742e35 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 3 Apr 2019 15:28:00 -0700 Subject: [PATCH] Fix webviews in same view column not always getting correct state change fired for visibility Fixes #70859 --- .../api/electron-browser/mainThreadWebview.ts | 1 - .../contrib/webview/browser/webviewEditorInput.ts | 13 +++---------- .../webview/browser/webviewEditorInputFactory.ts | 4 +--- .../contrib/webview/browser/webviewEditorService.ts | 8 +++----- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts index 5092e6d8cfa..2d2340bdef6 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts @@ -112,7 +112,6 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews }; this._webviews.set(handle, webview); - this._activeWebview = handle; /* __GDPR__ "webviews:createWebviewPanel" : { diff --git a/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts b/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts index f4671f2a482..0df01ea4d6f 100644 --- a/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts +++ b/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts @@ -72,7 +72,6 @@ export class WebviewEditorInput extends EditorInput { constructor( public readonly viewType: string, - id: number, name: string, options: WebviewInputOptions, state: any, @@ -85,8 +84,7 @@ export class WebviewEditorInput extends EditorInput { ) { super(); - this._id = id; - WebviewEditorInput.handlePool = Math.max(id, WebviewEditorInput.handlePool) + 1; + this._id = WebviewEditorInput.handlePool++; this._name = name; this._options = options; @@ -99,10 +97,6 @@ export class WebviewEditorInput extends EditorInput { return WebviewEditorInput.typeId; } - public getId(): number { - return this._id; - } - private readonly _onDidChangeIcon = this._register(new Emitter()); public readonly onDidChangeIcon = this._onDidChangeIcon.event; @@ -157,7 +151,7 @@ export class WebviewEditorInput extends EditorInput { } public matches(other: IEditorInput): boolean { - return other === this || (other instanceof WebviewEditorInput && other._id === this._id); + return other === this; } public get group(): GroupIdentifier | undefined { @@ -312,7 +306,6 @@ export class RevivedWebviewEditorInput extends WebviewEditorInput { constructor( viewType: string, - id: number, name: string, options: WebviewInputOptions, state: any, @@ -324,7 +317,7 @@ export class RevivedWebviewEditorInput extends WebviewEditorInput { private readonly reviver: (input: WebviewEditorInput) => Promise, @IWorkbenchLayoutService partService: IWorkbenchLayoutService, ) { - super(viewType, id, name, options, state, events, extension, partService); + super(viewType, name, options, state, events, extension, partService); } public async resolve(): Promise { diff --git a/src/vs/workbench/contrib/webview/browser/webviewEditorInputFactory.ts b/src/vs/workbench/contrib/webview/browser/webviewEditorInputFactory.ts index d79b00c8037..ee11107fdab 100644 --- a/src/vs/workbench/contrib/webview/browser/webviewEditorInputFactory.ts +++ b/src/vs/workbench/contrib/webview/browser/webviewEditorInputFactory.ts @@ -17,7 +17,6 @@ interface SerializedIconPath { interface SerializedWebview { readonly viewType: string; - readonly id: number; readonly title: string; readonly options: WebviewInputOptions; readonly extensionLocation: string | UriComponents | undefined; @@ -44,7 +43,6 @@ export class WebviewEditorInputFactory implements IEditorInputFactory { const data: SerializedWebview = { viewType: input.viewType, - id: input.getId(), title: input.getName(), options: input.options, extensionLocation: input.extension ? input.extension.location : undefined, @@ -69,7 +67,7 @@ export class WebviewEditorInputFactory implements IEditorInputFactory { const extensionLocation = reviveUri(data.extensionLocation); const extensionId = data.extensionId ? new ExtensionIdentifier(data.extensionId) : undefined; const iconPath = reviveIconPath(data.iconPath); - return this._webviewService.reviveWebview(data.viewType, data.id, data.title, iconPath, data.state, data.options, extensionLocation ? { + return this._webviewService.reviveWebview(data.viewType, data.title, iconPath, data.state, data.options, extensionLocation ? { location: extensionLocation, id: extensionId } : undefined, data.group); diff --git a/src/vs/workbench/contrib/webview/browser/webviewEditorService.ts b/src/vs/workbench/contrib/webview/browser/webviewEditorService.ts index 8581f7b8975..b12720c63ff 100644 --- a/src/vs/workbench/contrib/webview/browser/webviewEditorService.ts +++ b/src/vs/workbench/contrib/webview/browser/webviewEditorService.ts @@ -39,7 +39,6 @@ export interface IWebviewEditorService { reviveWebview( viewType: string, - id: number, title: string, iconPath: { light: URI, dark: URI } | undefined, state: any, @@ -143,7 +142,7 @@ export class WebviewEditorService implements IWebviewEditorService { }, events: WebviewEvents ): WebviewEditorInput { - const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, undefined, title, options, {}, events, extension); + const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, title, options, {}, events, extension); this._editorService.openEditor(webviewInput, { pinned: true, preserveFocus: showOptions.preserveFocus }, showOptions.group); return webviewInput; } @@ -165,7 +164,6 @@ export class WebviewEditorService implements IWebviewEditorService { public reviveWebview( viewType: string, - id: number, title: string, iconPath: { light: URI, dark: URI } | undefined, state: any, @@ -176,7 +174,7 @@ export class WebviewEditorService implements IWebviewEditorService { }, group: number | undefined, ): WebviewEditorInput { - const webviewInput = this._instantiationService.createInstance(RevivedWebviewEditorInput, viewType, id, title, options, state, {}, extension, async (webview: WebviewEditorInput): Promise => { + const webviewInput = this._instantiationService.createInstance(RevivedWebviewEditorInput, viewType, title, options, state, {}, extension, async (webview: WebviewEditorInput): Promise => { const didRevive = await this.tryRevive(webview); if (didRevive) { return Promise.resolve(undefined); @@ -220,7 +218,7 @@ export class WebviewEditorService implements IWebviewEditorService { // Revived webviews may not have an actively registered reviver but we still want to presist them // since a reviver should exist when it is actually needed. - return !(webview instanceof RevivedWebviewEditorInput); + return webview instanceof RevivedWebviewEditorInput; } private async tryRevive( -- GitLab