提交 53792db2 编写于 作者: B Benjamin Pasero

add closeEditors()

上级 9461a5e1
......@@ -32,6 +32,7 @@ export interface IEditorGroup {
getEditors(mru?: boolean): EditorInput[];
openEditor(editor: EditorInput, options?: IEditorOpenOptions): void;
closeEditor(editor: EditorInput): void;
closeEditors(except: EditorInput, direction?: Direction): void;
closeAllEditors(): void;
setActive(editor: EditorInput): void;
isActive(editor: EditorInput): boolean;
......@@ -66,8 +67,6 @@ export interface IEditorOpenOptions {
/// --- API-End ----
// Close Others
// Close Editors to the Right
// Move Editor
// Move Group
......@@ -273,6 +272,32 @@ export class EditorGroup implements IEditorGroup {
this._onEditorClosed.fire(editor);
}
public closeEditors(except: EditorInput, direction: Direction): void {
const index = this.indexOf(except);
if (index === -1) {
return; // not found
}
// Close to the left
if (direction === Direction.LEFT) {
for (let i = index - 1; i >= 0; i--) {
this.closeEditor(this.editors[i]);
}
}
// Close to the right
else if (direction === Direction.RIGHT) {
for (let i = this.editors.length - 1; i > index; i--) {
this.closeEditor(this.editors[i]);
}
}
// Both directions
else {
this.mru.filter(e => e !== except).forEach(e => this.closeEditor(e));
}
}
public closeAllEditors(): void {
// Optimize: close all non active editors first to produce less upstream work
......
......@@ -600,6 +600,62 @@ suite('Editor Stacks Model', () => {
assert.equal(group.count, 3);
});
test('Stack - Multiple Editors - Close Others, Close Left, Close Right', function () {
const model = create();
const group = model.openGroup('group');
const input1 = input();
const input2 = input();
const input3 = input();
const input4 = input();
const input5 = input();
group.openEditor(input1, { active: true, pinned: true });
group.openEditor(input2, { active: true, pinned: true });
group.openEditor(input3, { active: true, pinned: true });
group.openEditor(input4, { active: true, pinned: true });
group.openEditor(input5, { active: true, pinned: true });
// Close Others
group.closeEditors(group.activeEditor);
assert.equal(group.activeEditor, input5);
assert.equal(group.count, 1);
group.closeAllEditors();
group.openEditor(input1, { active: true, pinned: true });
group.openEditor(input2, { active: true, pinned: true });
group.openEditor(input3, { active: true, pinned: true });
group.openEditor(input4, { active: true, pinned: true });
group.openEditor(input5, { active: true, pinned: true });
group.setActive(input3);
// Close Left
assert.equal(group.activeEditor, input3);
group.closeEditors(group.activeEditor, Direction.LEFT);
assert.equal(group.activeEditor, input3);
assert.equal(group.count, 3);
assert.equal(group.getEditors()[0], input3);
assert.equal(group.getEditors()[1], input4);
assert.equal(group.getEditors()[2], input5);
group.closeAllEditors();
group.openEditor(input1, { active: true, pinned: true });
group.openEditor(input2, { active: true, pinned: true });
group.openEditor(input3, { active: true, pinned: true });
group.openEditor(input4, { active: true, pinned: true });
group.openEditor(input5, { active: true, pinned: true });
group.setActive(input3);
// Close Right
assert.equal(group.activeEditor, input3);
group.closeEditors(group.activeEditor, Direction.RIGHT);
assert.equal(group.activeEditor, input3);
assert.equal(group.count, 3);
assert.equal(group.getEditors()[0], input1);
assert.equal(group.getEditors()[1], input2);
assert.equal(group.getEditors()[2], input3);
});
test('Stack - Multiple Editors - real user example', function () {
const model = create();
const group = model.openGroup('group');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册