Skip to content

Commit 58583a7

Browse files
author
Benjamin Pasero
committed
1 parent 8108fc5 commit 58583a7

6 files changed

Lines changed: 37 additions & 10 deletions

File tree

src/vs/platform/editor/common/editor.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,26 @@ export interface IResourceInput extends IBaseResourceInput {
8282
export enum EditorActivation {
8383

8484
/**
85-
* Activate the editor after it opened.
85+
* Activate the editor after it opened. This will automatically restore
86+
* the editor if it is minimized.
8687
*/
8788
ACTIVATE,
8889

90+
/**
91+
* Only restore the editor if it is minimized but do not activate it.
92+
*
93+
* Note: will only work in combination with the `preserveFocus: true` option.
94+
* Otherwise, if focus moves into the editor, it will activate and restore
95+
* automatically.
96+
*/
97+
RESTORE,
98+
8999
/**
90100
* Preserve the current active editor.
91101
*
92-
* Note: will only work in combination with the
93-
* `preserveFocus: true` option.
102+
* Note: will only work in combination with the `preserveFocus: true` option.
103+
* Otherwise, if focus moves into the editor, it will activate and restore
104+
* automatically.
94105
*/
95106
PRESERVE
96107
}
@@ -107,7 +118,8 @@ export interface IEditorOptions {
107118

108119
/**
109120
* This option is only relevant if an editor is opened into a group that is not active
110-
* already and allows to control if the inactive group should become active or not.
121+
* already and allows to control if the inactive group should become active, restored
122+
* or preserved.
111123
*
112124
* By default, the editor group will become active unless `preserveFocus` or `inactive`
113125
* is specified.

src/vs/workbench/api/browser/mainThreadEditors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
119119
preserveFocus: options.preserveFocus,
120120
pinned: options.pinned,
121121
selection: options.selection,
122-
activation: options.preserveFocus ? EditorActivation.PRESERVE : undefined // preserve pre 1.38 behaviour to not make group active when preserveFocus: true
122+
// preserve pre 1.38 behaviour to not make group active when preserveFocus: true
123+
// but make sure to restore the editor to fix https://github.com/microsoft/vscode/issues/79633
124+
activation: options.preserveFocus ? EditorActivation.RESTORE : undefined
123125
};
124126

125127
const input: IResourceInput = {

src/vs/workbench/browser/parts/editor/editorGroupView.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,13 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
838838
if (options && options.activation === EditorActivation.ACTIVATE) {
839839
// Respect option to force activate an editor group.
840840
activateGroup = true;
841+
} else if (options && options.activation === EditorActivation.RESTORE) {
842+
// Respect option to force restore an editor group.
843+
restoreGroup = true;
841844
} else if (options && options.activation === EditorActivation.PRESERVE) {
842845
// Respect option to preserve active editor group.
843846
activateGroup = false;
847+
restoreGroup = false;
844848
} else if (openEditorOptions.active) {
845849
// Finally, we only activate/restore an editor which is
846850
// opening as active editor.

src/vs/workbench/common/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ export class EditorOptions implements IEditorOptions {
722722

723723
/**
724724
* This option is only relevant if an editor is opened into a group that is not active
725-
* already and allows to control if the inactive group should become active or not.
725+
* already and allows to control if the inactive group should become active, restored
726+
* or preserved.
726727
*
727728
* By default, the editor group will become active unless `preserveFocus` or `inactive`
728729
* is specified.

src/vs/workbench/contrib/webview/browser/webviewEditorService.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ export class WebviewEditorService implements IWebviewEditorService {
150150
this._editorService.openEditor(webviewInput, {
151151
pinned: true,
152152
preserveFocus: showOptions.preserveFocus,
153-
activation: showOptions.preserveFocus ? EditorActivation.PRESERVE : undefined // preserve pre 1.38 behaviour to not make group active when preserveFocus: true
153+
// preserve pre 1.38 behaviour to not make group active when preserveFocus: true
154+
// but make sure to restore the editor to fix https://github.com/microsoft/vscode/issues/79633
155+
activation: showOptions.preserveFocus ? EditorActivation.RESTORE : undefined
154156
}, showOptions.group);
155157
return webviewInput;
156158
}
@@ -163,7 +165,9 @@ export class WebviewEditorService implements IWebviewEditorService {
163165
if (webview.group === group.id) {
164166
this._editorService.openEditor(webview, {
165167
preserveFocus,
166-
activation: preserveFocus ? EditorActivation.PRESERVE : undefined // preserve pre 1.38 behaviour to not make group active when preserveFocus: true
168+
// preserve pre 1.38 behaviour to not make group active when preserveFocus: true
169+
// but make sure to restore the editor to fix https://github.com/microsoft/vscode/issues/79633
170+
activation: preserveFocus ? EditorActivation.RESTORE : undefined
167171
}, webview.group);
168172
} else {
169173
const groupView = this._editorGroupService.getGroup(webview.group!);

src/vs/workbench/services/editor/test/browser/editorService.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { workbenchInstantiationService, TestStorageService } from 'vs/workbench/
1212
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
1313
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
1414
import { EditorService, DelegatingEditorService } from 'vs/workbench/services/editor/browser/editorService';
15-
import { IEditorGroup, IEditorGroupsService, GroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService';
15+
import { IEditorGroup, IEditorGroupsService, GroupDirection, GroupsArrangement } from 'vs/workbench/services/editor/common/editorGroupsService';
1616
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
1717
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
1818
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
@@ -408,7 +408,7 @@ suite('EditorService', () => {
408408
assert.equal(editor!.group, part.groups[1]);
409409
});
410410

411-
test('pasero editor group activation', async () => {
411+
test('editor group activation', async () => {
412412
const partInstantiator = workbenchInstantiationService();
413413

414414
const part = partInstantiator.createInstance(EditorPart);
@@ -443,6 +443,10 @@ suite('EditorService', () => {
443443

444444
editor = await service.openEditor(input2, { pinned: true, activation: EditorActivation.ACTIVATE }, sideGroup);
445445
assert.equal(part.activeGroup, sideGroup);
446+
447+
part.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
448+
editor = await service.openEditor(input1, { pinned: true, preserveFocus: true, activation: EditorActivation.RESTORE }, rootGroup);
449+
assert.equal(part.activeGroup, sideGroup);
446450
});
447451

448452
test('active editor change / visible editor change events', async function () {

0 commit comments

Comments
 (0)