matchSet method

Set<NavNodeId> matchSet()

Ids that match the current query, plus their ancestors (so the matches are reachable). Empty when not filtering.

Implementation

Set<NavNodeId> matchSet() {
  final q = _query.trim().toLowerCase();
  if (q.isEmpty) return const {};
  final matched = <NavNodeId>{};
  final onPath = <NavNodeId>{};
  void rec(List<NavNode<T>> nodes, List<NavNodeId> path) {
    for (final n in nodes) {
      if (n.label.toLowerCase().contains(q)) {
        matched.add(n.id);
        onPath.addAll(path);
      }
      if (n.hasChildren) rec(n.children, [...path, n.id]);
    }
  }

  for (final s in _sections) {
    rec(s.items, const []);
  }
  return {...matched, ...onPath};
}