diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index 8ab806c05e4f9e18b89f16fdc96eda7700a100cd..65e7ec7713c8de8850cd0b3fdc0dbec21d51e493 100644 --- a/src/vs/platform/editor/common/editor.ts +++ b/src/vs/platform/editor/common/editor.ts @@ -82,15 +82,26 @@ export interface IResourceInput extends IBaseResourceInput { export enum EditorActivation { /** - * Activate the editor after it opened. + * Activate the editor after it opened. This will automatically restore + * the editor if it is minimized. */ ACTIVATE, + /** + * Only restore the editor if it is minimized but do not activate it. + * + * Note: will only work in combination with the `preserveFocus: true` option. + * Otherwise, if focus moves into the editor, it will activate and restore + * automatically. + */ + RESTORE, + /** * Preserve the current active editor. * - * Note: will only work in combination with the - * `preserveFocus: true` option. + * Note: will only work in combination with the `preserveFocus: true` option. + * Otherwise, if focus moves into the editor, it will activate and restore + * automatically. */ PRESERVE } @@ -107,7 +118,8 @@ export interface IEditorOptions { /** * This option is only relevant if an editor is opened into a group that is not active - * already and allows to control if the inactive group should become active or not. + * already and allows to control if the inactive group should become active, restored + * or preserved. * * By default, the editor group will become active unless `preserveFocus` or `inactive` * is specified. diff --git a/src/vs/workbench/api/browser/mainThreadEditors.ts b/src/vs/workbench/api/browser/mainThreadEditors.ts index ad52c83dd81b97b8b48b9a81a75dd5e5f30a1155..c4658d50a69f990fb4117f62566f8a31337d5489 100644 --- a/src/vs/workbench/api/browser/mainThreadEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadEditors.ts @@ -119,7 +119,9 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { preserveFocus: options.preserveFocus, pinned: options.pinned, selection: options.selection, - activation: options.preserveFocus ? EditorActivation.PRESERVE : undefined // preserve pre 1.38 behaviour to not make group active when preserveFocus: true + // 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: options.preserveFocus ? EditorActivation.RESTORE : undefined }; const input: IResourceInput = { diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index 6746bb5a1a7132cefd0a9dbbfe663dcb56aaf529..dda9116bc9a97e9b6685543d4de6ceed17abf320 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -838,9 +838,13 @@ export class EditorGroupView extends Themable implements IEditorGroupView { if (options && options.activation === EditorActivation.ACTIVATE) { // Respect option to force activate an editor group. activateGroup = true; + } else if (options && options.activation === EditorActivation.RESTORE) { + // Respect option to force restore an editor group. + restoreGroup = true; } else if (options && options.activation === EditorActivation.PRESERVE) { // Respect option to preserve active editor group. activateGroup = false; + restoreGroup = false; } else if (openEditorOptions.active) { // Finally, we only activate/restore an editor which is // opening as active editor. diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 6ced76994fe74920726ada18dc318db86ee00f4a..17c7331042019a66535394a2fe50918b8986b3f5 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -722,7 +722,8 @@ export class EditorOptions implements IEditorOptions { /** * This option is only relevant if an editor is opened into a group that is not active - * already and allows to control if the inactive group should become active or not. + * already and allows to control if the inactive group should become active, restored + * or preserved. * * By default, the editor group will become active unless `preserveFocus` or `inactive` * is specified. diff --git a/src/vs/workbench/contrib/webview/browser/webviewEditorService.ts b/src/vs/workbench/contrib/webview/browser/webviewEditorService.ts index 5b4b25119392660c283788c40b722a2cfdc4ce1f..17d4bbe919eefff17d75f3a9ef6b0bec39cc6a41 100644 --- a/src/vs/workbench/contrib/webview/browser/webviewEditorService.ts +++ b/src/vs/workbench/contrib/webview/browser/webviewEditorService.ts @@ -150,7 +150,9 @@ export class WebviewEditorService implements IWebviewEditorService { this._editorService.openEditor(webviewInput, { pinned: true, preserveFocus: showOptions.preserveFocus, - activation: showOptions.preserveFocus ? EditorActivation.PRESERVE : undefined // preserve pre 1.38 behaviour to not make group active when preserveFocus: true + // 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: showOptions.preserveFocus ? EditorActivation.RESTORE : undefined }, showOptions.group); return webviewInput; } @@ -163,7 +165,9 @@ export class WebviewEditorService implements IWebviewEditorService { if (webview.group === group.id) { this._editorService.openEditor(webview, { preserveFocus, - activation: preserveFocus ? EditorActivation.PRESERVE : undefined // preserve pre 1.38 behaviour to not make group active when preserveFocus: true + // 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!); diff --git a/src/vs/workbench/services/editor/test/browser/editorService.test.ts b/src/vs/workbench/services/editor/test/browser/editorService.test.ts index 258d85d6e216101c1248c0d67b775cb8d2981262..5475b191ee6cba10c06cf7818f68b6a6dd3a8585 100644 --- a/src/vs/workbench/services/editor/test/browser/editorService.test.ts +++ b/src/vs/workbench/services/editor/test/browser/editorService.test.ts @@ -12,7 +12,7 @@ import { workbenchInstantiationService, TestStorageService } from 'vs/workbench/ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput'; import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService'; import { EditorService, DelegatingEditorService } from 'vs/workbench/services/editor/browser/editorService'; -import { IEditorGroup, IEditorGroupsService, GroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService'; +import { IEditorGroup, IEditorGroupsService, GroupDirection, GroupsArrangement } from 'vs/workbench/services/editor/common/editorGroupsService'; import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; @@ -408,7 +408,7 @@ suite('EditorService', () => { assert.equal(editor!.group, part.groups[1]); }); - test('pasero editor group activation', async () => { + test('editor group activation', async () => { const partInstantiator = workbenchInstantiationService(); const part = partInstantiator.createInstance(EditorPart); @@ -443,6 +443,10 @@ suite('EditorService', () => { editor = await service.openEditor(input2, { pinned: true, activation: EditorActivation.ACTIVATE }, sideGroup); assert.equal(part.activeGroup, sideGroup); + + part.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS); + editor = await service.openEditor(input1, { pinned: true, preserveFocus: true, activation: EditorActivation.RESTORE }, rootGroup); + assert.equal(part.activeGroup, sideGroup); }); test('active editor change / visible editor change events', async function () {