Skip to content

Commit d2ac0ce

Browse files
authored
Open Editors: revisit order of groups to be based on visual order (for microsoft#56084) (microsoft#56264)
1 parent 2959c85 commit d2ac0ce

3 files changed

Lines changed: 29 additions & 16 deletions

File tree

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,16 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
419419
// Mark preferred size as changed
420420
this.resetPreferredSize();
421421

422-
// Events for groupd that got added
422+
// Events for groups that got added
423423
this.getGroups(GroupsOrder.GRID_APPEARANCE).forEach(groupView => {
424424
if (currentGroupViews.indexOf(groupView) === -1) {
425425
this._onDidAddGroup.fire(groupView);
426426
}
427427
});
428428

429+
// Update labels
430+
this.updateGroupLabels();
431+
429432
// Restore focus as needed
430433
if (gridHasFocus) {
431434
this._activeGroup.focus();
@@ -475,6 +478,9 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
475478
// Event
476479
this._onDidAddGroup.fire(newGroupView);
477480

481+
// Update labels
482+
this.updateGroupLabels();
483+
478484
return newGroupView;
479485
}
480486

@@ -631,12 +637,8 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
631637
this._activeGroup.focus();
632638
}
633639

634-
// Update labels: since our labels are created using the index of the
635-
// group, removing a group might produce gaps. So we iterate over all
636-
// groups and reassign the label based on the index.
637-
this.getGroups(GroupsOrder.CREATION_TIME).forEach((group, index) => {
638-
group.setLabel(this.getGroupLabel(index + 1));
639-
});
640+
// Update labels
641+
this.updateGroupLabels();
640642

641643
// Update container
642644
this.updateContainer();
@@ -648,10 +650,6 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
648650
this._onDidRemoveGroup.fire(groupView);
649651
}
650652

651-
private getGroupLabel(index: number): string {
652-
return localize('groupLabel', "Group {0}", index);
653-
}
654-
655653
moveGroup(group: IEditorGroupView | GroupIdentifier, location: IEditorGroupView | GroupIdentifier, direction: GroupDirection): IEditorGroupView {
656654
const sourceView = this.assertGroupView(group);
657655
const targetView = this.assertGroupView(location);
@@ -887,6 +885,21 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
887885
toggleClass(this.container, 'empty', this.isEmpty());
888886
}
889887

888+
private updateGroupLabels(): void {
889+
890+
// Since our labels are created using the index of the
891+
// group, adding/removing a group might produce gaps.
892+
// So we iterate over all groups and reassign the label
893+
// based on the index.
894+
this.getGroups(GroupsOrder.GRID_APPEARANCE).forEach((group, index) => {
895+
group.setLabel(this.getGroupLabel(index + 1));
896+
});
897+
}
898+
899+
private getGroupLabel(index: number): string {
900+
return localize('groupLabel', "Group {0}", index);
901+
}
902+
890903
private isEmpty(): boolean {
891904
return this.groupViews.size === 1 && this._activeGroup.isEmpty();
892905
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export abstract class BaseEditorPicker extends QuickOpenHandler {
117117

118118
// Sorting
119119
if (query.value) {
120-
const groups = this.editorGroupService.getGroups(GroupsOrder.CREATION_TIME);
120+
const groups = this.editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE);
121121
entries.sort((e1, e2) => {
122122
if (e1.group !== e2.group) {
123123
return groups.indexOf(e1.group) - groups.indexOf(e2.group); // older groups first
@@ -206,7 +206,7 @@ export class AllEditorsPicker extends BaseEditorPicker {
206206
protected getEditorEntries(): EditorPickerEntry[] {
207207
const entries: EditorPickerEntry[] = [];
208208

209-
this.editorGroupService.getGroups(GroupsOrder.CREATION_TIME).forEach(group => {
209+
this.editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE).forEach(group => {
210210
group.editors.forEach(editor => {
211211
entries.push(this.instantiationService.createInstance(EditorPickerEntry, editor, group));
212212
});

src/vs/workbench/parts/files/electron-browser/views/openEditorsView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IAction, ActionRunner } from 'vs/base/common/actions';
1010
import * as dom from 'vs/base/browser/dom';
1111
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1212
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
13-
import { IEditorGroupsService, IEditorGroup, GroupChangeKind } from 'vs/workbench/services/group/common/editorGroupsService';
13+
import { IEditorGroupsService, IEditorGroup, GroupChangeKind, GroupsOrder } from 'vs/workbench/services/group/common/editorGroupsService';
1414
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
1515
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1616
import { IEditorInput } from 'vs/workbench/common/editor';
@@ -326,7 +326,7 @@ export class OpenEditorsView extends ViewletPanel {
326326

327327
private get elements(): (IEditorGroup | OpenEditor)[] {
328328
const result: (IEditorGroup | OpenEditor)[] = [];
329-
this.editorGroupService.groups.forEach(g => {
329+
this.editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE).forEach(g => {
330330
if (this.showGroups) {
331331
result.push(g);
332332
}
@@ -342,7 +342,7 @@ export class OpenEditorsView extends ViewletPanel {
342342
return index;
343343
}
344344

345-
for (let g of this.editorGroupService.groups) {
345+
for (let g of this.editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE)) {
346346
if (g.id === group.id) {
347347
return index + (!!editor ? 1 : 0);
348348
} else {

0 commit comments

Comments
 (0)