Skip to content

Commit 92979f5

Browse files
committed
Aux window: improve MRU order of editor groups (fix microsoft#199529)
1 parent 877c92f commit 92979f5

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { localize } from 'vs/nls';
77
import { EditorGroupLayout, GroupDirection, GroupLocation, GroupOrientation, GroupsArrangement, GroupsOrder, IAuxiliaryEditorPart, IAuxiliaryEditorPartCreateEvent, IEditorDropTargetDelegate, IEditorGroupsService, IEditorSideGroup, IFindGroupScope, IMergeGroupOptions } from 'vs/workbench/services/editor/common/editorGroupsService';
88
import { Emitter } from 'vs/base/common/event';
9-
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
9+
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
1010
import { GroupIdentifier } from 'vs/workbench/common/editor';
1111
import { EditorPart, MainEditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
1212
import { IEditorGroupView, IEditorPartsView } from 'vs/workbench/browser/parts/editor/editor';
@@ -23,6 +23,8 @@ export class EditorParts extends MultiWindowParts<EditorPart> implements IEditor
2323

2424
readonly mainPart = this._register(this.createMainEditorPart());
2525

26+
private readonly mostRecentActiveParts = [this.mainPart];
27+
2628
constructor(
2729
@IInstantiationService private readonly instantiationService: IInstantiationService
2830
) {
@@ -82,10 +84,13 @@ export class EditorParts extends MultiWindowParts<EditorPart> implements IEditor
8284

8385
private registerEditorPartListeners(part: EditorPart, disposables: DisposableStore): void {
8486
disposables.add(part.onDidFocus(() => {
87+
this.doUpdateMostRecentActive(part, true);
88+
8589
if (this._parts.size > 1) {
8690
this._onDidActiveGroupChange.fire(this.activeGroup); // this can only happen when we have more than 1 editor part
8791
}
8892
}));
93+
disposables.add(toDisposable(() => this.doUpdateMostRecentActive(part)));
8994

9095
disposables.add(part.onDidChangeActiveGroup(group => this._onDidActiveGroupChange.fire(group)));
9196
disposables.add(part.onDidAddGroup(group => this._onDidAddGroup.fire(group)));
@@ -98,6 +103,20 @@ export class EditorParts extends MultiWindowParts<EditorPart> implements IEditor
98103
disposables.add(part.onDidChangeGroupLocked(group => this._onDidChangeGroupLocked.fire(group)));
99104
}
100105

106+
private doUpdateMostRecentActive(part: EditorPart, makeMostRecentlyActive?: boolean): void {
107+
const index = this.mostRecentActiveParts.indexOf(part);
108+
109+
// Remove from MRU list
110+
if (index !== -1) {
111+
this.mostRecentActiveParts.splice(index, 1);
112+
}
113+
114+
// Add to front as needed
115+
if (makeMostRecentlyActive) {
116+
this.mostRecentActiveParts.unshift(part);
117+
}
118+
}
119+
101120
private getGroupsLabel(index: number): string {
102121
return localize('groupLabel', "Window {0}", index + 1);
103122
}
@@ -186,10 +205,14 @@ export class EditorParts extends MultiWindowParts<EditorPart> implements IEditor
186205
getGroups(order = GroupsOrder.CREATION_TIME): IEditorGroupView[] {
187206
if (this._parts.size > 1) {
188207
let parts: EditorPart[];
189-
if (order === GroupsOrder.MOST_RECENTLY_ACTIVE) {
190-
parts = distinct([this.activePart, ...this._parts]); // put active part first in this order
191-
} else {
192-
parts = this.parts;
208+
switch (order) {
209+
case GroupsOrder.GRID_APPEARANCE: // we currently do not have a way to compute by appearance over multiple windows
210+
case GroupsOrder.CREATION_TIME:
211+
parts = this.parts;
212+
break;
213+
case GroupsOrder.MOST_RECENTLY_ACTIVE:
214+
parts = distinct([...this.mostRecentActiveParts, ...this.parts]); // always ensure all parts are included
215+
break;
193216
}
194217

195218
return parts.map(part => part.getGroups(order)).flat();

0 commit comments

Comments
 (0)