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

allow to open at index

上级 156f3c59
......@@ -66,6 +66,7 @@ export interface IEditorStacksModel {
export interface IEditorOpenOptions {
pinned?: boolean;
active?: boolean;
index?: number;
}
export enum Direction {
......@@ -197,8 +198,13 @@ export class EditorGroup implements IEditorGroup {
if (makePinned || !this.preview) {
const indexOfActive = this.indexOf(this.active);
// Insert into specific position
if (options && typeof options.index === 'number') {
this.splice(options.index, false, editor);
}
// Insert to the RIGHT of active editor
if (CONFIG_OPEN_EDITOR_DIRECTION === Direction.RIGHT) {
else if (CONFIG_OPEN_EDITOR_DIRECTION === Direction.RIGHT) {
this.splice(indexOfActive + 1, false, editor);
}
......@@ -246,6 +252,11 @@ export class EditorGroup implements IEditorGroup {
if (makeActive) {
this.setActive(editor);
}
// Respect index
if (options && typeof options.index === 'number') {
this.moveEditor(editor, options.index);
}
}
}
......
......@@ -642,11 +642,60 @@ suite('Editor Stacks Model', () => {
assert.equal(group.getEditors()[4], input5);
});
test('Stack - Multiple Editors - move editor across groups', function () {
const model = create();
const group1 = model.openGroup('group1');
const group2 = model.openGroup('group1');
const g1_input1 = input();
const g1_input2 = input();
const g2_input1 = input();
group1.openEditor(g1_input1, { active: true, pinned: true });
group1.openEditor(g1_input2, { active: true, pinned: true });
group2.openEditor(g2_input1, { active: true, pinned: true });
// A move across groups is a close in the one group and an open in the other group at a specific index
group2.closeEditor(g2_input1);
group1.openEditor(g2_input1, { active: true, pinned: true, index: 1 });
assert.equal(group1.count, 3);
assert.equal(group1.getEditors()[0], g1_input1);
assert.equal(group1.getEditors()[1], g2_input1);
assert.equal(group1.getEditors()[2], g1_input2);
});
test('Stack - Multiple Editors - move editor across groups (input already exists in group 1)', function () {
const model = create();
const group1 = model.openGroup('group1');
const group2 = model.openGroup('group1');
const g1_input1 = input();
const g1_input2 = input();
const g1_input3 = input();
const g2_input1 = g1_input2;
group1.openEditor(g1_input1, { active: true, pinned: true });
group1.openEditor(g1_input2, { active: true, pinned: true });
group1.openEditor(g1_input3, { active: true, pinned: true });
group2.openEditor(g2_input1, { active: true, pinned: true });
// A move across groups is a close in the one group and an open in the other group at a specific index
group2.closeEditor(g2_input1);
group1.openEditor(g2_input1, { active: true, pinned: true, index: 0 });
assert.equal(group1.count, 3);
assert.equal(group1.getEditors()[0], g1_input2);
assert.equal(group1.getEditors()[1], g1_input1);
assert.equal(group1.getEditors()[2], g1_input3);
});
test('Stack - Multiple Editors - Pinned & Non Active', function () {
const model = create();
const group = model.openGroup('group');
const input1 = input();
group.openEditor(input1);
assert.equal(group.activeEditor, input1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册