mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
meta-} goes to next buffer
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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'
|
||||
Reference in New Issue
Block a user