 
 
   addNode: (node) ->
+    @endNodeEdit()
     @undoRedoManager.createAndExecuteCommand 'addNode',
       execute: => @_addNode node
       undo: => @_removeNode node
 
   removeNode: (nodeKey) ->
+    @endNodeEdit()
     node = @nodeKeys[nodeKey]
 
     # create a copy of the list of links

    @updateListeners()

  moveNodeCompleted: (nodeKey, pos, originalPos) ->
    node = @nodeKeys[nodeKey]
    return unless node
    @undoRedoManager.createAndExecuteCommand 'moveNode',



  removeLink: (link) ->
    @endNodeEdit()
    @undoRedoManager.createAndExecuteCommand 'removeLink',
      execute: => @_removeLink link
      undo: => @_addLink link
