diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index a9f020799..f53f407fd 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -2588,3 +2588,29 @@ describe "Editor", -> expect(buffer.lineForRow(14)).toBe '' expect(buffer.lineForRow(15)).toBeUndefined() expect(editor.getCursorBufferPosition()).toEqual [14, 0] + + describe ".moveEditSessionAtIndex(fromIndex, toIndex)", -> + it "updates the edit session order", -> + jsPath = editor.getPath() + rootView.open("sample.txt") + txtPath = editor.getPath() + expect(editor.editSessions[0].getPath()).toBe jsPath + expect(editor.editSessions[1].getPath()).toBe txtPath + editor.moveEditSessionAtIndex(0, 1) + expect(editor.editSessions[0].getPath()).toBe txtPath + expect(editor.editSessions[1].getPath()).toBe jsPath + + it "fires an editor:edit-session-order-changed event", -> + eventHandler = jasmine.createSpy("eventHandler") + rootView.open("sample.txt") + editor.on "editor:edit-session-order-changed", eventHandler + editor.moveEditSessionAtIndex(0, 1) + expect(eventHandler).toHaveBeenCalled() + + it "sets the moved session as the editor's active session", -> + jsPath = editor.getPath() + rootView.open("sample.txt") + txtPath = editor.getPath() + expect(editor.activeEditSession.getPath()).toBe txtPath + editor.moveEditSessionAtIndex(0, 1) + expect(editor.activeEditSession.getPath()).toBe jsPath diff --git a/src/app/editor.coffee b/src/app/editor.coffee index d9472f86b..d002ddd16 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -549,6 +549,12 @@ class Editor extends View "Cancel" ) + moveEditSessionAtIndex: (fromIndex, toIndex) -> + editSession = @editSessions.splice(fromIndex, 1) + @editSessions.splice(toIndex, 0, editSession[0]) + @trigger 'editor:edit-session-order-changed' + @setActiveEditSessionIndex(toIndex) + transferEditSessionAtIndex: (fromIndex, toIndex, toEditor) -> toEditor.editSessions.splice(toIndex, 0, @editSessions.splice(fromIndex, 1)[0])