       _.remove(@editSessions, editSession)
 
   loadNextEditSession: ->
-    nextIndex = (@activeEditSessionIndex + 1) % @editSessions.length
+    nextIndex = (@getActiveEditSessionIndex() + 1) % @editSessions.length
     @setActiveEditSessionIndex(nextIndex)
 
   loadPreviousEditSession: ->
-    previousIndex = @activeEditSessionIndex - 1
+    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]

  isFocused: false
  softTabs: true
  tabText: '  '
  editSessions: null
  attached: false
  lineOverdraw: 100


  serialize: ->
    @saveActiveEditSession()

    viewClass: "Editor"
    editSessions: @editSessions.map (session) -> session.serialize()
    activeEditSessionIndex: @getActiveEditSessionIndex()
    isFocused: @isFocused

  copy: ->
    Editor.deserialize(@serialize(), @rootView())
