Skip to content

Commit 101335e

Browse files
author
Benjamin Pasero
committed
Editors: mru list in editor group not ideal when opening inactive editors (fix microsoft#86801)
1 parent cc1ba3c commit 101335e

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

src/vs/workbench/common/editor/editorGroup.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,19 @@ export class EditorGroup extends Disposable {
486486

487487
// Add
488488
if (!del && editor) {
489-
this.mru.push(editor); // make it LRU editor
489+
if (this.mru.length === 0) {
490+
// the list of most recent editors is empty
491+
// so this editor can only be the most recent
492+
this.mru.push(editor);
493+
} else {
494+
// we have most recent editors. as such we
495+
// put this newly opened editor right after
496+
// the current most recent one because it cannot
497+
// be the most recently active one unless
498+
// it becomes active. but it is still more
499+
// active then any other editor in the list.
500+
this.mru.splice(1, 0, editor);
501+
}
490502
}
491503

492504
// Remove / Replace
@@ -546,7 +558,7 @@ export class EditorGroup extends Disposable {
546558
// Remove old index
547559
this.mru.splice(mruIndex, 1);
548560

549-
// Set editor to front
561+
// Set editor as most recent one (first)
550562
this.mru.unshift(editor);
551563
}
552564

src/vs/workbench/test/common/editor/editorGroups.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ suite('Workbench editor groups', () => {
521521

522522
const mru = group.getEditors(true);
523523
assert.equal(mru[0], input1);
524-
assert.equal(mru[1], input2);
525-
assert.equal(mru[2], input3);
524+
assert.equal(mru[1], input3);
525+
assert.equal(mru[2], input2);
526526
});
527527

528528
test('Multiple Editors - Preview gets overwritten', function () {
@@ -1115,12 +1115,12 @@ suite('Workbench editor groups', () => {
11151115
assert.equal(group2.previewEditor!.matches(g2_input2), true);
11161116

11171117
assert.equal(group1.getEditors(true)[0].matches(g1_input2), true);
1118-
assert.equal(group1.getEditors(true)[1].matches(g1_input1), true);
1119-
assert.equal(group1.getEditors(true)[2].matches(g1_input3), true);
1118+
assert.equal(group1.getEditors(true)[1].matches(g1_input3), true);
1119+
assert.equal(group1.getEditors(true)[2].matches(g1_input1), true);
11201120

11211121
assert.equal(group2.getEditors(true)[0].matches(g2_input1), true);
1122-
assert.equal(group2.getEditors(true)[1].matches(g2_input2), true);
1123-
assert.equal(group2.getEditors(true)[2].matches(g2_input3), true);
1122+
assert.equal(group2.getEditors(true)[1].matches(g2_input3), true);
1123+
assert.equal(group2.getEditors(true)[2].matches(g2_input2), true);
11241124

11251125
// Create model again - should load from storage
11261126
group1 = inst.createInstance(EditorGroup, group1.serialize());
@@ -1134,12 +1134,12 @@ suite('Workbench editor groups', () => {
11341134
assert.equal(group2.previewEditor!.matches(g2_input2), true);
11351135

11361136
assert.equal(group1.getEditors(true)[0].matches(g1_input2), true);
1137-
assert.equal(group1.getEditors(true)[1].matches(g1_input1), true);
1138-
assert.equal(group1.getEditors(true)[2].matches(g1_input3), true);
1137+
assert.equal(group1.getEditors(true)[1].matches(g1_input3), true);
1138+
assert.equal(group1.getEditors(true)[2].matches(g1_input1), true);
11391139

11401140
assert.equal(group2.getEditors(true)[0].matches(g2_input1), true);
1141-
assert.equal(group2.getEditors(true)[1].matches(g2_input2), true);
1142-
assert.equal(group2.getEditors(true)[2].matches(g2_input3), true);
1141+
assert.equal(group2.getEditors(true)[1].matches(g2_input3), true);
1142+
assert.equal(group2.getEditors(true)[2].matches(g2_input2), true);
11431143
});
11441144

11451145
test('Single group, multiple editors - persist (some not persistable)', function () {
@@ -1172,18 +1172,18 @@ suite('Workbench editor groups', () => {
11721172
assert.equal(group.previewEditor!.matches(nonSerializableInput2), true);
11731173

11741174
assert.equal(group.getEditors(true)[0].matches(nonSerializableInput2), true);
1175-
assert.equal(group.getEditors(true)[1].matches(serializableInput1), true);
1176-
assert.equal(group.getEditors(true)[2].matches(serializableInput2), true);
1175+
assert.equal(group.getEditors(true)[1].matches(serializableInput2), true);
1176+
assert.equal(group.getEditors(true)[2].matches(serializableInput1), true);
11771177

11781178
// Create model again - should load from storage
11791179
group = inst.createInstance(EditorGroup, group.serialize());
11801180

11811181
assert.equal(group.count, 2);
1182-
assert.equal(group.activeEditor!.matches(serializableInput1), true);
1182+
assert.equal(group.activeEditor!.matches(serializableInput2), true);
11831183
assert.equal(group.previewEditor, null);
11841184

1185-
assert.equal(group.getEditors(true)[0].matches(serializableInput1), true);
1186-
assert.equal(group.getEditors(true)[1].matches(serializableInput2), true);
1185+
assert.equal(group.getEditors(true)[0].matches(serializableInput2), true);
1186+
assert.equal(group.getEditors(true)[1].matches(serializableInput1), true);
11871187
});
11881188

11891189
test('Multiple groups, multiple editors - persist (some not persistable, causes empty group)', function () {

0 commit comments

Comments
 (0)