diff --git a/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts b/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts index d355e0876c4..5e00e96f690 100644 --- a/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts +++ b/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts @@ -17,7 +17,7 @@ import { WebviewIcons } from 'vs/workbench/contrib/webviewPanel/browser/webviewI import { ICreateWebViewShowOptions, IWebviewWorkbenchService } from 'vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService'; import { columnToEditorGroup, editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; -import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; /** @@ -154,11 +154,10 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc initData: extHostProtocol.IWebviewInitData, showOptions: extHostProtocol.WebviewPanelShowOptions, ): void { - const mainThreadShowOptions: ICreateWebViewShowOptions = Object.create(null); - if (showOptions) { - mainThreadShowOptions.preserveFocus = !!showOptions.preserveFocus; - mainThreadShowOptions.group = columnToEditorGroup(this._editorGroupService, showOptions.viewColumn); - } + const mainThreadShowOptions: ICreateWebViewShowOptions = showOptions ? { + preserveFocus: !!showOptions.preserveFocus, + group: columnToEditorGroup(this._editorGroupService, showOptions.viewColumn) + } : {}; const extension = reviveWebviewExtension(extensionData); @@ -198,10 +197,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc return; } - const targetGroup = this._editorGroupService.getGroup(columnToEditorGroup(this._editorGroupService, showOptions.viewColumn)) || this._editorGroupService.getGroup(webview.group || 0); - if (targetGroup) { - this._webviewWorkbenchService.revealWebview(webview, targetGroup, !!showOptions.preserveFocus); - } + this._webviewWorkbenchService.revealWebview(webview, showOptions.viewColumn ?? ACTIVE_GROUP, !!showOptions.preserveFocus); } public $registerSerializer(viewType: string, options: { serializeBuffersForPostMessage: boolean }): void { diff --git a/src/vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService.ts b/src/vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService.ts index 28657c3f0a6..b7d52c8e8cc 100644 --- a/src/vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService.ts +++ b/src/vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService.ts @@ -13,19 +13,19 @@ import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle' import { EditorActivation } from 'vs/platform/editor/common/editor'; import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { GroupIdentifier } from 'vs/workbench/common/editor'; -import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; -import { IWebviewService, WebviewContentOptions, WebviewExtensionDescription, WebviewOptions, IOverlayWebview } from 'vs/workbench/contrib/webview/browser/webview'; +import { EditorInput } from 'vs/workbench/common/editor/editorInput'; +import { IOverlayWebview, IWebviewService, WebviewContentOptions, WebviewExtensionDescription, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview'; import { WebviewIconManager, WebviewIcons } from 'vs/workbench/contrib/webviewPanel/browser/webviewIconManager'; -import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; +import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; import { ACTIVE_GROUP_TYPE, IEditorService, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService'; import { WebviewInput } from './webviewEditorInput'; export const IWebviewWorkbenchService = createDecorator('webviewEditorService'); export interface ICreateWebViewShowOptions { - group: IEditorGroup | GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE; - preserveFocus: boolean; + readonly group?: IEditorGroup | GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE; + readonly preserveFocus?: boolean; } export interface IWebviewWorkbenchService { @@ -57,7 +57,7 @@ export interface IWebviewWorkbenchService { revealWebview( webview: WebviewInput, - group: IEditorGroup, + group: IEditorGroup | GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE, preserveFocus: boolean ): void; @@ -168,7 +168,6 @@ export class WebviewEditorService extends Disposable implements IWebviewWorkbenc private readonly _iconManager: WebviewIconManager; constructor( - @IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService, @IEditorService private readonly _editorService: IEditorService, @IInstantiationService private readonly _instantiationService: IInstantiationService, @IWebviewService private readonly _webviewService: IWebviewService, @@ -241,27 +240,20 @@ export class WebviewEditorService extends Disposable implements IWebviewWorkbenc public revealWebview( webview: WebviewInput, - group: IEditorGroup, + group: IEditorGroup | GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE, preserveFocus: boolean ): void { const topLevelEditor = this.findTopLevelEditorForWebview(webview); - if (webview.group === group.id) { - if (this._editorService.activeEditor === topLevelEditor) { - return; - } - - this._editorService.openEditor(topLevelEditor, { - preserveFocus, - // preserve pre 1.38 behaviour to not make group active when preserveFocus: true - // but make sure to restore the editor to fix https://github.com/microsoft/vscode/issues/79633 - activation: preserveFocus ? EditorActivation.RESTORE : undefined - }, webview.group); - } else { - const groupView = this._editorGroupService.getGroup(webview.group!); - if (groupView) { - groupView.moveEditor(topLevelEditor, group, { preserveFocus }); - } + if (this._editorService.activeEditor === topLevelEditor) { + return; } + + this._editorService.openEditor(topLevelEditor, { + preserveFocus, + // preserve pre 1.38 behaviour to not make group active when preserveFocus: true + // but make sure to restore the editor to fix https://github.com/microsoft/vscode/issues/79633 + activation: preserveFocus ? EditorActivation.RESTORE : undefined + }, group); } private findTopLevelEditorForWebview(webview: WebviewInput): EditorInput {