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 liveBrackets+ buffer, memoized on theDocument. A fold add/remove (FoldSet::generationbump) 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. ManualPartialEq(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
Patchremap in the commit path (seeFoldSet::apply_patch); the extent is resolved from theBracketspass inFoldMap::new, so folds survive edits and undo/redo with no interior bookkeeping to drift. - Inline
Fold - 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, socloseremains a real, addressable buffer position. - Visible
Row - A visible display row, resolved back to its buffer row — the render driver.