hideAllExcept static method

void hideAllExcept(
  1. Object? rootId
)

Hides all roots except the given root and its ancestors/descendants.

Implementation

static void hideAllExcept(Object? rootId) {
  if (rootId == null) return;
  final allowedRoots = <Object>{};

  // Add current and all ancestors
  Object? current = rootId;
  while (current != null) {
    allowedRoots.add(current);
    current = _roots[current]?.parentRootId;
  }

  // Add all descendants of allowed roots
  void addDescendants(Object id) {
    for (final child in _roots.values.where((r) => r.parentRootId == id)) {
      if (allowedRoots.add(child.rootId)) {
        addDescendants(child.rootId);
      }
    }
  }

  for (final id in allowedRoots.toList()) {
    addDescendants(id);
  }

  final toHide = _roots.keys.where((k) => !allowedRoots.contains(k)).toList();
  for (final k in toHide) {
    hideRoot(k);
  }
}