meta-{ goes to previous buffer

This commit is contained in:
Corey Johnson
2012-04-11 13:41:54 -07:00
parent bf367863ba
commit 5097218aa2
3 changed files with 26 additions and 2 deletions

View File

@@ -2097,8 +2097,7 @@ describe "Editor", ->
editor.buffer.setPath("new.txt")
expect(eventHandler).toHaveBeenCalled()
fdescribe ".loadNextEditorState()", ->
describe ".loadNextEditorState()", ->
it "loads the next editor state and wraps to beginning when end is reached", ->
buffer0 = new Buffer("0")
buffer1 = new Buffer("1")
@@ -2114,3 +2113,20 @@ describe "Editor", ->
expect(editor.buffer.path).toBe "1"
editor.loadNextEditorState()
expect(editor.buffer.path).toBe "2"
describe ".loadPreviousEditorState()", ->
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.loadPreviousEditorState()
expect(editor.buffer.path).toBe "1"
editor.loadPreviousEditorState()
expect(editor.buffer.path).toBe "0"
editor.loadPreviousEditorState()
expect(editor.buffer.path).toBe "2"

View File

@@ -85,6 +85,7 @@ class Editor extends View
@on 'split-down', => @splitDown()
@on 'close', => @remove(); false
@on 'show-next-buffer', => @loadNextEditorState()
@on 'show-previous-buffer', => @loadPreviousEditorState()
@on 'move-to-top', => @moveCursorToTop()
@on 'move-to-bottom', => @moveCursorToBottom()
@@ -251,6 +252,12 @@ class Editor extends View
nextIndex = (index + 1) % @editorStates.length
@setEditorState(@editorStates[nextIndex])
loadPreviousEditorState: ->
index = @indexOfEditorState(@getEditorState())
if index?
previousIndex = if --index >= 0 then index else @editorStates.length - 1
@setEditorState(@editorStates[previousIndex])
setEditorState: (editorState={}) ->
buffer = editorState.buffer ?= new Buffer
@setEditorStateForBuffer(buffer, editorState)

View File

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