 
   serialize: ->
     @saveActiveEditSession()
-    editSessions = @editSessions.map (session) -> session.serialize()
-    { viewClass: "Editor", editSessions, @activeEditSessionIndex, @isFocused }
+
+    viewClass: "Editor"
+    editSessions: @editSessions.map (session) -> session.serialize()
+    activeEditSessionIndex: @getActiveEditSessionIndex()
+    isFocused: @isFocused
 
   copy: ->
     Editor.deserialize(@serialize(), @rootView())

      @activeEditSession.off()

    @activeEditSession = @editSessions[index]
    @activeEditSessionIndex = index

    @unsubscribeFromBuffer() if @buffer
    @buffer = @activeEditSession.buffer

      _.remove(@editSessions, editSession)

  loadNextEditSession: ->
    nextIndex = (@getActiveEditSessionIndex() + 1) % @editSessions.length
    @setActiveEditSessionIndex(nextIndex)

  loadPreviousEditSession: ->
    previousIndex = @getActiveEditSessionIndex() - 1
    previousIndex = @editSessions.length - 1 if previousIndex < 0
    @setActiveEditSessionIndex(previousIndex)

  getActiveEditSessionIndex: ->
    return index for session, index in @editSessions when session == @activeEditSession

  setActiveEditSessionIndex: (index) ->
    throw new Error("Edit session not found") unless @editSessions[index]
