     @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
+    existingEditorState = @getEditorStateForBuffer(buffer)
+    if existingEditorState
+      _.extend(existingEditorState, editorState)
+    else
+      @editorStates.push(editorState)
+
   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
+  setEditorState: (editorState={}) ->
+    buffer = editorState.buffer ?= new Buffer
+    @setEditorStateForBuffer(buffer, editorState)
     @setBuffer(buffer)
 
   getEditorState: ->

    scrollLeft: @scroller.scrollLeft()

  saveEditorStateForCurrentBuffer: ->
    @editorStatesByBufferId[@buffer.id] = @getEditorState()

  handleBufferChange: (e) ->
    @compositeCursor.handleBufferChange(e)

    @autoIndent = true
    @buildCursorAndSelection()
    @handleEvents()
    @editorStates = []
    @setEditorState(editorState)

  bindKeys: ->
