pub struct FoldIndex { /* private fields */ }Expand description
Sorted in canonical (start_row ASC, end_row DESC) order over a fold slice
for O(log F) “is this row hidden by a closed fold” queries.
The O(log F) twin of folds.iter().any(|f| f.hides(row)). Closed
folds’ (start_row, end_row] hidden ranges are merged into a disjoint
union, and one partition_point over the merged ranges answers the
query. Merging (not just sorting) is what keeps this correct for
nested folds: a fold that starts inside an enclosing one can end
before it while the enclosing fold still covers the query row, so
“the last fold with start_row <= row” alone is not enough — that
fold may have already ended while an earlier, longer one still hides
the row.
Mirrors the TUI renderer’s FoldIndex (hjkl-buffer-tui
render.rs) — the same merge, the same query, the same answers. That
copy sorts its input defensively because its fold source is not
guaranteed ordered; this one relies on the buffer’s canonical
(start_row ASC, end_row DESC) ordering invariant (see
crate::View::add_fold and crate::View::set_auto_folds) and skips the
sort so the build stays O(F) — it runs per keystroke / per frame on hot
paths. Debug builds assert the invariant, so feeding unsorted folds fails
loudly in tests rather than silently mis-answering in release.