Skip to content

Commit

Permalink
editor groups - resolve #96725 (#96820)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored May 4, 2020
1 parent 3f3d17e commit fd5d9a3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/common/editor/editorGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ export class EditorGroup extends Disposable {
return null;
}));

this.mru = data.mru.map(i => this.editors[i]);
this.mru = coalesce(data.mru.map(i => this.editors[i]));

this.active = this.mru[0];

Expand Down
44 changes: 40 additions & 4 deletions src/vs/workbench/test/browser/parts/editor/editorGroups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,18 @@ interface ISerializedTestInput {

class TestEditorInputFactory implements IEditorInputFactory {

static disableSerialize = false;
static disableDeserialize = false;

canSerialize(editorInput: EditorInput): boolean {
return true;
}

serialize(editorInput: EditorInput): string {
serialize(editorInput: EditorInput): string | undefined {
if (TestEditorInputFactory.disableSerialize) {
return undefined;
}

let testEditorInput = <TestEditorInput>editorInput;
let testInput: ISerializedTestInput = {
id: testEditorInput.id
Expand All @@ -158,7 +165,11 @@ class TestEditorInputFactory implements IEditorInputFactory {
return JSON.stringify(testInput);
}

deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput {
deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput | undefined {
if (TestEditorInputFactory.disableDeserialize) {
return undefined;
}

let testInput: ISerializedTestInput = JSON.parse(serializedEditorInput);

return new TestEditorInput(testInput.id);
Expand All @@ -170,6 +181,9 @@ suite('Workbench editor groups', () => {
let disposables: IDisposable[] = [];

setup(() => {
TestEditorInputFactory.disableSerialize = false;
TestEditorInputFactory.disableDeserialize = false;

disposables.push(Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerEditorInputFactory('testEditorInputForGroups', TestEditorInputFactory));
});

Expand Down Expand Up @@ -296,18 +310,40 @@ suite('Workbench editor groups', () => {
const input2 = input();
const input3 = input();

// Pinned and Active
// Case 1: inputs can be serialized and deserialized

group.openEditor(input1, { pinned: true, active: true });
group.openEditor(input2, { pinned: true, active: true });
group.openEditor(input3, { pinned: false, active: true });

const deserialized = createGroup(group.serialize());
let deserialized = createGroup(group.serialize());
assert.equal(group.id, deserialized.id);
assert.equal(deserialized.count, 3);
assert.equal(deserialized.getEditors(EditorsOrder.SEQUENTIAL).length, 3);
assert.equal(deserialized.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 3);
assert.equal(deserialized.isPinned(input1), true);
assert.equal(deserialized.isPinned(input2), true);
assert.equal(deserialized.isPinned(input3), false);
assert.equal(deserialized.isActive(input3), true);

// Case 2: inputs cannot be serialized
TestEditorInputFactory.disableSerialize = true;

deserialized = createGroup(group.serialize());
assert.equal(group.id, deserialized.id);
assert.equal(deserialized.count, 0);
assert.equal(deserialized.getEditors(EditorsOrder.SEQUENTIAL).length, 0);
assert.equal(deserialized.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 0);

// Case 3: inputs cannot be deserialized
TestEditorInputFactory.disableSerialize = false;
TestEditorInputFactory.disableDeserialize = true;

deserialized = createGroup(group.serialize());
assert.equal(group.id, deserialized.id);
assert.equal(deserialized.count, 0);
assert.equal(deserialized.getEditors(EditorsOrder.SEQUENTIAL).length, 0);
assert.equal(deserialized.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 0);
});

test('One Editor', function () {
Expand Down

0 comments on commit fd5d9a3

Please sign in to comment.