Editor.initialize calls setEditorState to set buffer, cursor position, etc

This commit is contained in:
Nathan Sobo
2012-04-10 17:39:41 -06:00
parent 447b0598f9
commit 5d8affb3e4

View File

@@ -39,7 +39,7 @@ class Editor extends View
softTabs: true
tabText: ' '
initialize: (editorState={}) ->
initialize: (editorState) ->
requireStylesheet 'editor.css'
requireStylesheet 'theme/twilight.css'
@@ -48,11 +48,8 @@ class Editor extends View
@autoIndent = true
@buildCursorAndSelection()
@handleEvents()
buffer = editorState.buffer ? new Buffer
@editorStatesByBufferId = {}
@editorStatesByBufferId[buffer.id] = editorState
@setBuffer(buffer)
@setEditorState(editorState)
bindKeys: ->
@on 'save', => @save()
@@ -228,6 +225,11 @@ class Editor extends View
@scroller.scrollTop(editorState.scrollTop ? 0)
@scroller.scrollLeft(editorState.scrollLeft ? 0)
setEditorState: (editorState) ->
buffer = editorState.buffer ? new Buffer
@editorStatesByBufferId[buffer.id] = editorState
@setBuffer(buffer)
getEditorState: ->
buffer: @buffer
cursorScreenPosition: @getCursorScreenPosition().copy()