pub struct FoldSet { /* private fields */ }Expand description
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.
Implementations§
Source§impl FoldSet
impl FoldSet
Sourcepub fn first_at_or_after(&self, offset: u32) -> Option<u32>
pub fn first_at_or_after(&self, offset: u32) -> Option<u32>
The smallest folded opener at byte offset or after, if any — an O(log)
probe into the opener-sorted set (e.g. “the fold headed on this row”),
not a scan of every fold.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
The mutation counter — the document’s FoldMap cache invalidates when it
changes (see the struct field).
Sourcepub fn fold(&mut self, open: u32) -> bool
pub fn fold(&mut self, open: u32) -> bool
Collapse the pair whose opener is at byte offset open. No-op returning
false if that opener is already folded. The caller vouches that open is
a foldable open bracket (see crate::Document::fold).
Sourcepub fn unfold(&mut self, open: u32) -> bool
pub fn unfold(&mut self, open: u32) -> bool
Unfold the pair whose opener is at open. Returns whether one was removed.
Sourcepub fn fold_all(&mut self, opens: impl IntoIterator<Item = u32>)
pub fn fold_all(&mut self, opens: impl IntoIterator<Item = u32>)
Collapse every opener in opens in ONE pass — one set mutation for the
whole batch. A multi-caret Ctrl+Shift+[ can collapse thousands of pairs at
once; calling Self::fold per item would be O(folds) each and O(folds²)
overall, so the batch path keeps a document-scale collapse linear. The
caller vouches each offset is a foldable open bracket.
Sourcepub fn unfold_all(&mut self, opens: &[u32])
pub fn unfold_all(&mut self, opens: &[u32])
Unfold every opener in opens in ONE pass — the batch mirror of
Self::unfold.
Sourcepub fn toggle(&mut self, open: u32) -> bool
pub fn toggle(&mut self, open: u32) -> bool
Fold the pair at open if not folded, else unfold it.
Sourcepub fn apply_patch(&mut self, patch: &Patch)
pub fn apply_patch(&mut self, patch: &Patch)
Shift every opener through a committed patch. Bias Right keeps the
offset tracking its bracket char (an insertion at the bracket pushes both
right together). An edit that deletes the opener maps it into the deletion;
FoldSet::reconcile then drops it (it is no longer a live bracket).
Sourcepub fn reconcile(&mut self, is_foldable_opener: impl Fn(u32) -> bool)
pub fn reconcile(&mut self, is_foldable_opener: impl Fn(u32) -> bool)
Drop every fold whose opener is no longer a live foldable open bracket.
is_foldable_opener answers “is this byte offset an open bracket with a
matched partner forming a foldable range?” (from the live Brackets
pass — see Document::reconcile_folds). Because the extent is
re-derived, there is nothing else to validate or heal.
Sourcepub fn openers_in(&self, range: Range<u32>) -> Vec<u32>
pub fn openers_in(&self, range: Range<u32>) -> Vec<u32>
The collapsed openers whose offset lies in range, ascending — the folds an
edit’s re-matched region could directly touch. O(log n + hits).
Sourcepub fn reconcile_only(
&mut self,
candidates: &[u32],
is_foldable_opener: impl Fn(u32) -> bool,
)
pub fn reconcile_only( &mut self, candidates: &[u32], is_foldable_opener: impl Fn(u32) -> bool, )
Windowed reconcile (reconcile’s twin): drop only the
candidates (a small, pre-narrowed set) that are no longer foldable. The
common case — a bracket edit that broke no fold — removes nothing and costs
only the O(candidates) predicate; the O(folds) retain runs (and is
counted) ONLY when a fold actually broke, which is the unavoidable Vec
compaction. Callers vouch every candidate is currently folded.