       'cursor-history:clear': => @clear()
       'cursor-history:dump':  => @dump()
       'cursor-history:toggle-debug': => @toggleConfig('debug')
+      'cursor-history:check-leak': => @checkLeak()
 
     @subscriptions.add atom.workspace.observeTextEditors (editor) =>
+      @editorSubscriptions[editor.id] = new CompositeDisposable
       @handleChangePath(editor)
-      @subscriptions.add editor.onDidChangeCursorPosition (event) =>
+
+      @editorSubscriptions[editor.id].add editor.onDidChangeCursorPosition (event) =>
         return if @isLocked()
         @handleCursorMoved event
+
+      # @editorSubscriptions[editor.id].add editor.onDidDestroy =>
+      #   @editorSubscriptions[editor.id].dispose()
+      #   delete @editorSubscriptions[editor.id]
 
     @subscriptions.add atom.workspace.observeActivePaneItem (item) =>
       if item instanceof TextEditor and item.getURI()

      Flasher.flash() if settings.get('flashOnLand')
      @history.dump direction

  handleChangePath: (editor) ->
    orgURI = editor.getURI()

    @subscriptions.add editor.onDidChangePath =>
      newURI = editor.getURI()
      @history.rename orgURI, newURI
      @lastEditor.rename orgURI, newURI


  deactivate: ->
    @subscriptions.dispose()
    for key, disposables @editorSubscriptions
      disposables.dispose()
    @editorSubscriptions = null
    settings.dispose()
    @history?.destroy()
    @history = null
