removeConnection method

void removeConnection(
  1. String connectionId
)

Removes a connection from the graph.

Also removes the connection from the selection set if it was selected.

Triggers the onConnectionDeleted callback after successful removal.

Throws ArgumentError if the connection doesn't exist.

Implementation

void removeConnection(String connectionId) {
  final connectionToDelete = _connections.firstWhere(
    (c) => c.id == connectionId,
    orElse: () => throw ArgumentError('Connection $connectionId not found'),
  );
  runInAction(() {
    _connections.removeWhere((c) => c.id == connectionId);
    _selectedConnectionIds.remove(connectionId);
    // Remove from spatial index
    _spatialIndex.removeConnection(connectionId);
  });

  // Remove cached path to prevent stale rendering
  _connectionPainter?.removeConnectionFromCache(connectionId);

  // Fire event after successful removal
  events.connection?.onDeleted?.call(connectionToDelete);
}