Skip to main content

Module fold_map

Module fold_map 

Source
Expand description

Code folding — bracket-anchored. A fold is a collapsed bracket pair, identified by the byte offset of its opener (([{). That offset is the only thing stored; it rides each committed transaction’s Patch via Patch::map_offset, and the fold’s extent (which rows are hidden) is re-derived from the live Brackets pass every frame.

Storing only the opener (never a hidden-interior byte range) is what keeps a fold from drifting onto an unrelated span: there is no interior offset to go stale. Reconcile is then trivial — a fold survives iff its opener is still a live, foldable open bracket. Rows are reconstructed each frame, so there is no persisted visual index to desync.

View state, not document state: folds never enter the buffer or the undo stack; they compose over the buffer as a second display layer the render/movement/hit-test paths consult.

Structs§

FoldMap
A fold-aware row converter — buffer rows ↔ display rows with folded interiors hidden. Resolved from a FoldSet + the live Brackets + buffer, memoized on the Document. A fold add/remove (FoldSet::generation bump) rebuilds it from scratch; every text edit shifts it in place through the patch (Self::apply_patch) — a no-line-change edit only moves inline offsets, and a line insert/remove reanchors the region tree’s affected seam — so plain typing over a document-scale fold set never pays an O(folds) rebuild. Manual PartialEq (decoded regions) so a test can deep-equal the incrementally-shifted map against a fresh build (the drift oracle).
FoldSet
The persistent, document-owned set of active folds. Each entry is the byte offset of one collapsed pair’s opening bracket, kept sorted and unique. Rides Patch remap in the commit path (see FoldSet::apply_patch); the extent is resolved from the Brackets pass in FoldMap::new, so folds survive edits and undo/redo with no interior bookkeeping to drift.
InlineFold
One resolved inline fold — a collapsed single-line bracket pair. It hides the bytes between the brackets (open+1..close) on one still-visible row, rendered [ … ]. The delimiters stay; only the interior collapses, so close remains a real, addressable buffer position.
VisibleRow
A visible display row, resolved back to its buffer row — the render driver.