Skip to main content

FoldMap

Struct FoldMap 

Source
pub struct FoldMap { /* private fields */ }
Expand description

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

Implementations§

Source§

impl FoldMap

Source

pub fn new(folds: &FoldSet, brackets: &Brackets, buffer: &Buffer) -> Self

Resolve the collapsed openers into visible block-fold regions against the live brackets + buffer. O(folds log brackets). An opener that is no longer a matched bracket, or whose pair is single-line, yields no block region (the latter is a future inline fold, not a row-hider).

Source

pub fn apply_patch(&mut self, patch: &Patch, buffer: &Buffer) -> bool

Shift this map through a committed edit’s patch IN PLACE, returning false (→ the caller rebuilds instead) when the edit changed the line count. A line insertion/removal moves block-region rows and the display prefix sums, which is not a cheap in-place update; a no-line-change edit (plain typing) leaves every block region, prefix sum, and the buffer row count unchanged and only moves inline-fold offsets — so this is O(inline folds), and O(0) for the common block-only “collapse all” case, far cheaper than the O(folds) rebuild the per-keystroke edit path would otherwise pay.

A fold whose interior an edit touches is expanded (removed) before this runs, so a surviving inline fold’s interior is intact — only its (and its close’s) offset shifts, exactly as FoldSet::apply_patch shifts the opener, keeping the two in lockstep. Fold add/remove bumps the generation and forces a rebuild, so this never has to reconcile the fold set.

Source

pub fn inline_fold_before(&self, off: u32) -> Option<InlineFold>

The last inline fold opening strictly before off (the only one that can hide off, since roots are disjoint) — O(log n). The offset-keyed lookup movement / hit-testing / the caret-eject path use.

Source

pub fn inline_fold_at(&self, opener: u32) -> Option<InlineFold>

The root inline fold opening exactly at opener, or None — O(log n) membership for the collapsed-chip hit-test. Roots are disjoint and open-sorted, so Self::inline_fold_before(opener+1) returns the last root with open ≤ opener; testing open == opener is then exact root membership. saturating_add guards the u32 edge; a nested (non-root) opener resolves to its enclosing root, whose open != openerNone — exactly what a linear inline_folds().binary_search membership test yields.

Source

pub fn inline_folds(&self) -> Vec<InlineFold>

The resolved inline (single-line) folds, sorted by opener offset — the render / caret / hit-test consult these to collapse a mid-line span.

Source

pub fn inline_folds_on_row(&self, row: u32) -> Vec<InlineFold>

The inline folds on buffer row, ascending by opener — the per-row render query (RowLayout). O(log n + hits): a row’s folds are a contiguous window.

Source

pub fn display_row_count(&self) -> u32

Number of display rows (buffer rows minus every hidden interior row).

Source

pub fn max_display_row(&self) -> DisplayRow

The last valid display row.

Source

pub fn to_display_row(&self, row: BufferRow) -> DisplayRow

Buffer row → display row. A hidden interior row clips to its header’s display row, so a collapsed fold’s interior renders at the header line.

Source

pub fn to_buffer_row(&self, row: DisplayRow) -> BufferRow

Display row → buffer row. Always a visible row (a header or an unfolded line), never a hidden interior.

Source

pub fn is_folded(&self, row: BufferRow) -> bool

Whether row is a hidden interior row of some fold.

Source

pub fn entry_edge_if_hidden(&self, buffer: &Buffer, offset: u32) -> Option<u32>

If offset is HIDDEN inside a collapsed fold, the caret’s eject target — a block’s header line end, or an inline gap’s left landable edge; None when visible. O(log folds) (regions and inline roots are sorted and disjoint), so a multi-caret fold pulls every hidden caret out in one O(carets·log folds) pass instead of an O(carets·folds) Self::display_position probe each — the “collapse all” ejection at document scale.

Source

pub fn fold_containing(&self, row: BufferRow) -> Option<(BufferRow, BufferRow)>

The collapsed root fold whose hidden interior contains row (i.e. header < row <= last), as (header, last). None if row is a header or not folded. Used by fold-aware horizontal movement to hop the collapsed gap between the header line and the inline closing tail.

Source

pub fn fold_at_header(&self, row: BufferRow) -> Option<BufferRow>

If row is a folded header, the fold’s last row (for the chip/chevron and placeholder). None if row is not a header of a collapsed fold.

Source

pub fn header_of_tail(&self, row: BufferRow) -> Option<BufferRow>

If row is the last (closing) row of a collapsed root fold, that fold’s header row — the display anchor for the fold’s inline closing tail. None otherwise. Roots are disjoint, so at most one fold ends on row. The inverse direction of Self::fold_at_header, for placing a caret / hit-testing a click on the collapsed line’s real closing bracket.

Source

pub fn display_window(&self, top_rows: f64, bottom_rows: f64) -> Range<u32>

The display-row window covering fractional rows [top_rows, bottom_rows) from the content top: floor the first visible row, ceil past the last, clamp to the row count. THE one owner of the render window rule — the widget derives the fractional rows from pixels (Self::display_row_at is its single-row sibling) and never floors/clamps itself. (f64 like Self::display_row_at: exact for every u32 row count, where f32 fractional rows degrade past ~2²³.)

Source

pub fn visible_rows( &self, window: Range<u32>, ) -> impl Iterator<Item = VisibleRow> + '_

The visible display rows in window (see Self::display_window), each resolved to its buffer row with the fold-header flag — the render loop’s driver. Hidden interior rows are simply not produced.

Source§

impl FoldMap

Source

pub fn row_layout<'a>( &self, buffer: &'a Buffer, row: BufferRow, tab: u32, ) -> RowLayout<'a>

The horizontal projection of visible buffer row — built per use, like the FoldMap itself; never store it.

Source

pub fn header_layout<'a>( &self, buffer: &'a Buffer, row: BufferRow, tab: u32, ) -> Option<HeaderLayout<'a>>

The head … tail one-line layout of row, iff it is a collapsed block fold’s header.

Source

pub fn display_position( &self, buffer: &Buffer, offset: u32, tab: u32, ) -> Option<DisplayPosition>

THE owner of “where does buffer offset render”: its display row and horizontal cell. Follows a collapsed block’s closing tail to the header row; clips a column hidden in an inline fold to its chip center. None iff the offset is genuinely hidden — inside a block fold’s gap, or on the last row before the visible tail.

Source

pub fn hit_row( &self, buffer: &Buffer, row: BufferRow, cell: f32, bias: Bias, tab: u32, ) -> u32

Inverse of Self::display_position on one visible row: a (fractional, unrounded) display cell → the byte offset a click there lands on, resolving a collapsed header’s gap (→ header line end) and tail (→ the last row’s column) before the plain row projection.

Source

pub fn display_row_at(&self, rows_from_top: f64) -> DisplayRow

THE pixel-y inversion policy, in row units: a (fractional) count of display rows from the content top → the display row it falls on, floored and clamped to the valid range. Every y-driven hit (clicks, hover, gutter, boxes) routes through this one rule.

f64, deliberately: f32 holds fractional rows exactly only below ~2²³ rows — past that, hits land on the wrong line and (via the widget’s px↔row maps) rendered rows visibly skip. f64 is exact for every u32-addressable document.

Trait Implementations§

Source§

impl Debug for FoldMap

Source§

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

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

impl Eq for FoldMap

Source§

impl PartialEq for FoldMap

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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, 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.