Try avoiding bad calls to columnToEditorGroup

Fixes #132421
This commit is contained in:
Matt Bierner 2021-11-15 14:48:48 -08:00
parent bb764173a3
commit 99739e607b
No known key found for this signature in database
GPG key ID: 099C331567E11888
2 changed files with 22 additions and 34 deletions

View file

@ -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 {

View file

@ -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<IWebviewWorkbenchService>('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 {