cancelConnectionDrag method

void cancelConnectionDrag()

Cancels a connection drag without creating a connection.

Call this from PortWidget's GestureDetector.onPanEnd when not over a valid target, or from onPanCancel when the gesture is interrupted.

Implementation

void cancelConnectionDrag() {
  // Reset highlighted port before canceling
  final temp = interaction.temporaryConnection.value;
  if (temp != null &&
      temp.targetNodeId != null &&
      temp.targetPortId != null) {
    final targetNode = _nodes[temp.targetNodeId!];
    if (targetNode != null) {
      final targetPort = targetNode.allPorts
          .where((p) => p.id == temp.targetPortId)
          .firstOrNull;
      if (targetPort != null) {
        runInAction(() => targetPort.highlighted.value = false);
      }
    }
  }

  interaction.cancelConnection();

  // Re-enable panning after connection drag ends
  // Cursor is derived from state via Observer in widget MouseRegions
  runInAction(() {
    interaction.panEnabled.value = true;
  });

  // Fire connection end event with failure
  events.connection?.onConnectEnd?.call(false);
}