提交 dc348340 编写于 作者: B Benjamin Pasero

editor groups - resolve #96725

上级 2348a4f2
...@@ -662,7 +662,7 @@ export class EditorGroup extends Disposable { ...@@ -662,7 +662,7 @@ export class EditorGroup extends Disposable {
return null; 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]; this.active = this.mru[0];
......
...@@ -145,11 +145,18 @@ interface ISerializedTestInput { ...@@ -145,11 +145,18 @@ interface ISerializedTestInput {
class TestEditorInputFactory implements IEditorInputFactory { class TestEditorInputFactory implements IEditorInputFactory {
static disableSerialize = false;
static disableDeserialize = false;
canSerialize(editorInput: EditorInput): boolean { canSerialize(editorInput: EditorInput): boolean {
return true; return true;
} }
serialize(editorInput: EditorInput): string { serialize(editorInput: EditorInput): string | undefined {
if (TestEditorInputFactory.disableSerialize) {
return undefined;
}
let testEditorInput = <TestEditorInput>editorInput; let testEditorInput = <TestEditorInput>editorInput;
let testInput: ISerializedTestInput = { let testInput: ISerializedTestInput = {
id: testEditorInput.id id: testEditorInput.id
...@@ -158,7 +165,11 @@ class TestEditorInputFactory implements IEditorInputFactory { ...@@ -158,7 +165,11 @@ class TestEditorInputFactory implements IEditorInputFactory {
return JSON.stringify(testInput); 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); let testInput: ISerializedTestInput = JSON.parse(serializedEditorInput);
return new TestEditorInput(testInput.id); return new TestEditorInput(testInput.id);
...@@ -170,6 +181,9 @@ suite('Workbench editor groups', () => { ...@@ -170,6 +181,9 @@ suite('Workbench editor groups', () => {
let disposables: IDisposable[] = []; let disposables: IDisposable[] = [];
setup(() => { setup(() => {
TestEditorInputFactory.disableSerialize = false;
TestEditorInputFactory.disableDeserialize = false;
disposables.push(Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerEditorInputFactory('testEditorInputForGroups', TestEditorInputFactory)); disposables.push(Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerEditorInputFactory('testEditorInputForGroups', TestEditorInputFactory));
}); });
...@@ -296,18 +310,40 @@ suite('Workbench editor groups', () => { ...@@ -296,18 +310,40 @@ suite('Workbench editor groups', () => {
const input2 = input(); const input2 = input();
const input3 = input(); const input3 = input();
// Pinned and Active // Case 1: inputs can be serialized and deserialized
group.openEditor(input1, { pinned: true, active: true }); group.openEditor(input1, { pinned: true, active: true });
group.openEditor(input2, { pinned: true, active: true }); group.openEditor(input2, { pinned: true, active: true });
group.openEditor(input3, { pinned: false, 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(group.id, deserialized.id);
assert.equal(deserialized.count, 3); 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(input1), true);
assert.equal(deserialized.isPinned(input2), true); assert.equal(deserialized.isPinned(input2), true);
assert.equal(deserialized.isPinned(input3), false); assert.equal(deserialized.isPinned(input3), false);
assert.equal(deserialized.isActive(input3), true); 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 () { test('One Editor', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册