rebuildConnectionSegmentsForNodes method

void rebuildConnectionSegmentsForNodes(
  1. List<String> nodeIds
)

Rebuilds connection spatial index using accurate path segments. Call this after drag ends to restore accurate hit-testing.

Implementation

void rebuildConnectionSegmentsForNodes(List<String> nodeIds) {
  if (!isConnectionPainterInitialized || _theme == null) return;

  final nodeIdSet = nodeIds.toSet();
  final pathCache = _connectionPainter!.pathCache;
  final connectionStyle = _theme!.connectionTheme.style;

  for (final connection in _connections) {
    if (nodeIdSet.contains(connection.sourceNodeId) ||
        nodeIdSet.contains(connection.targetNodeId)) {
      final sourceNode = _nodes[connection.sourceNodeId];
      final targetNode = _nodes[connection.targetNodeId];
      if (sourceNode == null || targetNode == null) continue;

      final segments = pathCache.getOrCreateSegmentBounds(
        connection: connection,
        sourceNode: sourceNode,
        targetNode: targetNode,
        connectionStyle: connectionStyle,
      );
      _spatialIndex.updateConnection(connection, segments);
    }
  }
}