mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Merge branch 'master' of github.com:github/atom
This commit is contained in:
@@ -2096,3 +2096,37 @@ describe "Editor", ->
|
||||
eventHandler.reset()
|
||||
editor.buffer.setPath("new.txt")
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
describe ".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"
|
||||
|
||||
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"
|
||||
|
||||
@@ -32,11 +32,11 @@ class CommandPanel extends View
|
||||
toggle: ->
|
||||
if @parent().length then @hide() else @show()
|
||||
|
||||
show: ->
|
||||
show: (text='') ->
|
||||
@rootView.append(this)
|
||||
@prompt.css 'font', @editor.css('font')
|
||||
@editor.focus()
|
||||
@editor.buffer.setText('')
|
||||
@editor.buffer.setText(text)
|
||||
|
||||
hide: ->
|
||||
@detach()
|
||||
|
||||
@@ -48,7 +48,7 @@ class Editor extends View
|
||||
@autoIndent = true
|
||||
@buildCursorAndSelection()
|
||||
@handleEvents()
|
||||
@editorStatesByBufferId = {}
|
||||
@editorStates = []
|
||||
@setEditorState(editorState)
|
||||
|
||||
bindKeys: ->
|
||||
@@ -84,6 +84,8 @@ class Editor extends View
|
||||
@on 'split-up', => @splitUp()
|
||||
@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()
|
||||
@@ -217,15 +219,48 @@ class Editor extends View
|
||||
@buffer.on "change.editor#{@id}", (e) => @handleBufferChange(e)
|
||||
@renderer.on 'change', (e) => @handleRendererChange(e)
|
||||
|
||||
getEditorStateForBuffer: (buffer) ->
|
||||
_.find @editorStates, (editorState) =>
|
||||
editorState.buffer.id == buffer.id
|
||||
|
||||
setEditorStateForBuffer: (buffer, editorState) ->
|
||||
editorState.buffer = buffer
|
||||
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 = (@editorStatesByBufferId[buffer.id] ?= {})
|
||||
editorState = @getEditorStateForBuffer(buffer)
|
||||
if not editorState
|
||||
editorState = {}
|
||||
@setEditorStateForBuffer(buffer, editorState)
|
||||
@setCursorScreenPosition(editorState.cursorScreenPosition ? [0, 0])
|
||||
@scroller.scrollTop(editorState.scrollTop ? 0)
|
||||
@scroller.scrollLeft(editorState.scrollLeft ? 0)
|
||||
|
||||
setEditorState: (editorState) ->
|
||||
buffer = editorState.buffer ? new Buffer
|
||||
@editorStatesByBufferId[buffer.id] = editorState
|
||||
loadNextEditorState: ->
|
||||
index = @indexOfEditorState(@getEditorState())
|
||||
if index?
|
||||
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)
|
||||
@setBuffer(buffer)
|
||||
@isFocused = editorState.isFocused
|
||||
|
||||
@@ -237,7 +272,7 @@ class Editor extends View
|
||||
isFocused: @isFocused
|
||||
|
||||
saveEditorStateForCurrentBuffer: ->
|
||||
@editorStatesByBufferId[@buffer.id] = @getEditorState()
|
||||
@setEditorStateForBuffer(@buffer, @getEditorState())
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
@compositeCursor.handleBufferChange(e)
|
||||
|
||||
@@ -30,4 +30,6 @@ 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-previous-buffer'
|
||||
'meta-}': 'show-next-buffer'
|
||||
@@ -25,10 +25,8 @@ class RootView extends View
|
||||
@createProject(path)
|
||||
|
||||
@on 'toggle-file-finder', => @toggleFileFinder()
|
||||
@on 'show-console', -> window.showConsole()
|
||||
@on 'find-in-file', =>
|
||||
@commandPanel.show()
|
||||
@commandPanel.editor.setText("/")
|
||||
@on 'show-console', => window.showConsole()
|
||||
@on 'find-in-file', => @commandPanel.show("/")
|
||||
|
||||
@one 'attach', => @focus()
|
||||
@on 'focus', (e) =>
|
||||
|
||||
Reference in New Issue
Block a user