endNodeDrag method

void endNodeDrag()

Ends a node drag operation.

Call this from NodeWidget's GestureDetector.onPanEnd.

Implementation

void endNodeDrag() {
  // Capture dragged nodes before clearing state
  final draggedNodes = <Node<T>>[];
  final draggedNodeIds = <String>[];
  for (final node in _nodes.values) {
    if (node.dragging.value) {
      draggedNodes.add(node);
      draggedNodeIds.add(node.id);
    }
  }

  runInAction(() {
    // Clear dragging state on nodes
    for (final node in draggedNodes) {
      node.dragging.value = false;
    }

    // Handle Command+drag group operations (add/remove from groups)
    final isCommandPressed = HardwareKeyboard.instance.isMetaPressed;
    for (final nodeId in draggedNodeIds) {
      annotations.handleCommandDragGroupOperation(nodeId, isCommandPressed);
    }

    // Clear drag highlight and drag state
    annotations.clearDragHighlight();
    interaction.draggedNodeId.value = null;
    interaction.lastPointerPosition.value = null;
  });

  // Rebuild connection segments with accurate path bounds after drag ends
  if (draggedNodeIds.isNotEmpty) {
    rebuildConnectionSegmentsForNodes(draggedNodeIds);
  }

  // Fire drag stop event for all dragged nodes
  for (final node in draggedNodes) {
    events.node?.onDragStop?.call(node);
  }
}