expandWire method

bool expandWire(
  1. String nodeId,
  2. String wireName
)

Partially expand a node to reveal a specific wire (hyperedge) by name.

Finds the hyperedge on nodeId whose hwMeta.name matches wireName, then reveals all child nodes connected by that hyperedge plus the hyperedge itself. Used by the search routine to show a wire without fully expanding the containing module.

Returns true if new children/edges were revealed.

Implementation

bool expandWire(String nodeId, String wireName) {
  final node = nodeMap[nodeId];
  if (node == null) {
    return false;
  }

  // Node must have hidden children for partial expansion to make sense.
  if (node.hiddenChildren == null || node.hiddenChildren!.isEmpty) {
    return false;
  }

  final hyperedges = node.hyperedges;
  if (hyperedges == null || hyperedges.isEmpty) {
    return false;
  }

  final matchingHyperedgeIds = <String>{};
  final connectedChildIds = <String>{};

  for (final h in hyperedges) {
    if (h.name != wireName) {
      continue;
    }

    matchingHyperedgeIds.add(h.id);
    for (final (nId, _) in h.sources) {
      if (nId != node.id) {
        connectedChildIds.add(nId);
      }
    }
    for (final (nId, _) in h.targets) {
      if (nId != node.id) {
        connectedChildIds.add(nId);
      }
    }
  }

  if (connectedChildIds.isEmpty && matchingHyperedgeIds.isEmpty) {
    return false;
  }

  // Check if everything is already visible (idempotent)
  final existingChildren = node.partialChildIds ?? {};
  final existingEdges = node.partialHyperedgeIds ?? {};
  if (existingChildren.containsAll(connectedChildIds) &&
      existingEdges.containsAll(matchingHyperedgeIds)) {
    return false;
  }

  // Additive: merge into existing partial sets.
  final mergedChildren = {...existingChildren, ...connectedChildIds};
  final mergedEdges = {...existingEdges, ...matchingHyperedgeIds};

  node
    ..partialChildIds = mergedChildren
    ..partialHyperedgeIds = mergedEdges;

  return true;
}