meta-} goes to next buffer

This commit is contained in:
Corey Johnson
2012-04-11 13:41:19 -07:00
parent 4bdc908b98
commit bf367863ba
3 changed files with 36 additions and 4 deletions

View File

@@ -2096,3 +2096,21 @@ describe "Editor", ->
eventHandler.reset()
editor.buffer.setPath("new.txt")
expect(eventHandler).toHaveBeenCalled()
fdescribe ".loadNextEditorState()", ->
it "loads the next editor state and wraps to beginning when end is reached", ->
buffer0 = new Buffer("0")
buffer1 = new Buffer("1")
buffer2 = new Buffer("2")
editor = new Editor {buffer: buffer0}
editor.setBuffer(buffer1)
editor.setBuffer(buffer2)
expect(editor.buffer.path).toBe "2"
editor.loadNextEditorState()
expect(editor.buffer.path).toBe "0"
editor.loadNextEditorState()
expect(editor.buffer.path).toBe "1"
editor.loadNextEditorState()
expect(editor.buffer.path).toBe "2"

View File

@@ -84,6 +84,7 @@ class Editor extends View
@on 'split-up', => @splitUp()
@on 'split-down', => @splitDown()
@on 'close', => @remove(); false
@on 'show-next-buffer', => @loadNextEditorState()
@on 'move-to-top', => @moveCursorToTop()
@on 'move-to-bottom', => @moveCursorToBottom()
@@ -223,12 +224,18 @@ class Editor extends View
setEditorStateForBuffer: (buffer, editorState) ->
editorState.buffer = buffer
existingEditorState = @getEditorStateForBuffer(buffer)
if existingEditorState
_.extend(existingEditorState, editorState)
index = @indexOfEditorState(editorState)
if index?
@editorStates[index] = editorState
else
@editorStates.push(editorState)
indexOfEditorState: (editorState) ->
for o, i in @editorStates
return i if o.buffer.id == editorState.buffer.id
return null
loadEditorStateForBuffer: (buffer) ->
editorState = @getEditorStateForBuffer(buffer)
if not editorState
@@ -238,6 +245,12 @@ class Editor extends View
@scroller.scrollTop(editorState.scrollTop ? 0)
@scroller.scrollLeft(editorState.scrollLeft ? 0)
loadNextEditorState: ->
index = @indexOfEditorState(@getEditorState())
if index?
nextIndex = (index + 1) % @editorStates.length
@setEditorState(@editorStates[nextIndex])
setEditorState: (editorState={}) ->
buffer = editorState.buffer ?= new Buffer
@setEditorStateForBuffer(buffer, editorState)

View File

@@ -30,4 +30,5 @@ window.keymap.bindKeys '.editor',
'alt-meta-up': 'split-up'
'alt-meta-down': 'split-down'
'meta-[': 'outdent-selected-rows'
'meta-]': 'indent-selected-rows'
'meta-]': 'indent-selected-rows'
'meta-}': 'show-next-buffer'