 
   operation = null
 
+  # Track changes in the cursor by
+  # temporarily using a pointer to it
+  if node.contains @cursor
+    @setCursor node.end.next, null, 'after'
+  cursor = @getCursor()
+
   if @inTree node
     operation = @tree.remove node
     @pushUndo operation
-    return operation
+
+  @setCursor cursor
 
   @prepareNode node, null
   return operation
 
 Editor::spliceIn = (node, location) ->
+  # Track changes in the cursor by temporarily
+  # using a pointer to it
+  cursor = @getCursor()
+
   container = location.container ? location.parent
   if container.type is 'block'
     container = container.parent
   else if container.type is 'socket' and
       container.start.next isnt container.end
     @spliceOut new model.List container.start.next, container.end.prev
+
+  @setCursor cursor
 
   @prepareNode node, container
   operation = @tree.insert location, node

Editor::getCursor = ->
  cursor = @tree.getFromLocation(@cursor)

  # If the cursor is incorrect (usually because something moved), find recover it
  until (not cursor?) or @validCursorPosition(cursor)
    cursor = cursor.next
  if not cursor?
    cursor = @tree.getFromLocation(@cursor)
    until @validCursorPosition(cursor)
      cursor = cursor.prev

  if cursor.type is 'socketStart'
    return cursor.container
  else

  return operation

Editor::redo = ->
  currentValue = @getSerializedEditorState()

  until @redoStack.length is 0 or
      (@redoStack[@redoStack.length - 1] is 'CAPTURE' and
      not @getSerializedEditorState().equals(currentValue))
    operation = @popRedo()
    if operation instanceof FloatingOperation
      @performFloatingOperation(operation, 'forward')
