From 58583a7b84132bb22a8dcd68ad2ad9dcb2f50fec Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 29 Aug 2019 08:29:23 +0200 Subject: [PATCH] fix #79633 --- src/vs/platform/editor/common/editor.ts | 20 +++++++++++++++---- .../api/browser/mainThreadEditors.ts | 4 +++- .../browser/parts/editor/editorGroupView.ts | 4 ++++ src/vs/workbench/common/editor.ts | 3 ++- .../webview/browser/webviewEditorService.ts | 8 ++++++-- .../editor/test/browser/editorService.test.ts | 8 ++++++-- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index 8ab806c05e4..65e7ec7713c 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 ad52c83dd81..c4658d50a69 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 6746bb5a1a7..dda9116bc9a 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 6ced76994fe..17c73310420 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 5b4b2511939..17d4bbe919e 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 258d85d6e21..5475b191ee6 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 () { -- GitLab