Skip to main content

FoldSet

Struct FoldSet 

Source
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

Source

pub fn new() -> Self

An empty fold set.

Source

pub fn is_empty(&self) -> bool

Whether nothing is folded.

Source

pub fn len(&self) -> usize

The number of active folds.

Source

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.

Source

pub fn generation(&self) -> u64

The mutation counter — the document’s FoldMap cache invalidates when it changes (see the struct field).

Source

pub fn clear(&mut self)

Unfold everything.

Source

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).

Source

pub fn unfold(&mut self, open: u32) -> bool

Unfold the pair whose opener is at open. Returns whether one was removed.

Source

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.

Source

pub fn unfold_all(&mut self, opens: &[u32])

Unfold every opener in opens in ONE pass — the batch mirror of Self::unfold.

Source

pub fn is_folded(&self, open: u32) -> bool

Whether the pair opening at open is folded.

Source

pub fn toggle(&mut self, open: u32) -> bool

Fold the pair at open if not folded, else unfold it.

Source

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).

Source

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.

Source

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).

Source

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.

Source

pub fn iter(&self) -> impl Iterator<Item = u32> + '_

The collapsed openers (offsets), ascending — for FoldMap and tests.

Trait Implementations§

Source§

impl Clone for FoldSet

Source§

fn clone(&self) -> FoldSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FoldSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FoldSet

Source§

fn default() -> FoldSet

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.