Support moving an edit session's editor index

This commit is contained in:
Kevin Sawicki 2013-02-11 18:36:32 -08:00
parent 5abf17e93b
commit a104e67acd
2 changed files with 32 additions and 0 deletions

View File

@ -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

View File

@ -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])