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



  addNode: (node) ->
    @undoRedoManager.createAndExecuteCommand 'addNode',
      execute: => @_addNode node
      undo: => @_removeNode node

  removeNode: (nodeKey) ->
    node = @nodeKeys[nodeKey]

    # create a copy of the list of links

    @updateListeners()

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