flattenVisible function

List<TomlVisibleRow> flattenVisible(
  1. TomlTableNode root, {
  2. required bool isExpanded(
    1. String path
    ),
  3. String? query,
  4. bool caseSensitive = false,
})

Flattens a TOML tree into the linear list of rows that are currently visible, so the viewer can render them with a lazy ListView.

Without a query, only expanded branches are walked, so the cost is proportional to what is on screen rather than to the document size.

With a query, the whole document is walked (a search has to look everywhere), non-matching branches are dropped, and the ancestors of every match are force-expanded so the hit is reachable.

Implementation

List<TomlVisibleRow> flattenVisible(
  TomlTableNode root, {
  required bool Function(String path) isExpanded,
  String? query,
  bool caseSensitive = false,
}) {
  final rows = <TomlVisibleRow>[];
  final normalized = query?.trim() ?? '';

  if (normalized.isEmpty) {
    _walk(root, isExpanded, rows);
    return rows;
  }

  final needle = caseSensitive ? normalized : normalized.toLowerCase();
  _search(root, needle, caseSensitive, isExpanded, rows);
  return rows;
}