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
impl FoldMap
Sourcepub fn new(folds: &FoldSet, brackets: &Brackets, buffer: &Buffer) -> Self
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).
Sourcepub fn apply_patch(&mut self, patch: &Patch, buffer: &Buffer) -> bool
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.
Sourcepub fn inline_fold_before(&self, off: u32) -> Option<InlineFold>
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.
Sourcepub fn inline_fold_at(&self, opener: u32) -> Option<InlineFold>
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 != opener → None —
exactly what a linear inline_folds().binary_search membership test yields.
Sourcepub fn inline_folds(&self) -> Vec<InlineFold>
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.
Sourcepub fn inline_folds_on_row(&self, row: u32) -> Vec<InlineFold>
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.
Sourcepub fn display_row_count(&self) -> u32
pub fn display_row_count(&self) -> u32
Number of display rows (buffer rows minus every hidden interior row).
Sourcepub fn max_display_row(&self) -> DisplayRow
pub fn max_display_row(&self) -> DisplayRow
The last valid display row.
Sourcepub fn to_display_row(&self, row: BufferRow) -> DisplayRow
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.
Sourcepub fn to_buffer_row(&self, row: DisplayRow) -> BufferRow
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.
Sourcepub fn is_folded(&self, row: BufferRow) -> bool
pub fn is_folded(&self, row: BufferRow) -> bool
Whether row is a hidden interior row of some fold.
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.
Sourcepub fn fold_containing(&self, row: BufferRow) -> Option<(BufferRow, BufferRow)>
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.
Sourcepub fn fold_at_header(&self, row: BufferRow) -> Option<BufferRow>
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.
Sourcepub fn header_of_tail(&self, row: BufferRow) -> Option<BufferRow>
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.
Sourcepub fn display_window(&self, top_rows: f64, bottom_rows: f64) -> Range<u32>
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²³.)
Sourcepub fn visible_rows(
&self,
window: Range<u32>,
) -> impl Iterator<Item = VisibleRow> + '_
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
impl FoldMap
Sourcepub fn row_layout<'a>(
&self,
buffer: &'a Buffer,
row: BufferRow,
tab: u32,
) -> RowLayout<'a>
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.
Sourcepub fn header_layout<'a>(
&self,
buffer: &'a Buffer,
row: BufferRow,
tab: u32,
) -> Option<HeaderLayout<'a>>
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.
Sourcepub fn display_position(
&self,
buffer: &Buffer,
offset: u32,
tab: u32,
) -> Option<DisplayPosition>
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.
Sourcepub fn hit_row(
&self,
buffer: &Buffer,
row: BufferRow,
cell: f32,
bias: Bias,
tab: u32,
) -> u32
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.
Sourcepub fn display_row_at(&self, rows_from_top: f64) -> DisplayRow
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§
Auto Trait Implementations§
impl Freeze for FoldMap
impl RefUnwindSafe for FoldMap
impl Send for FoldMap
impl Sync for FoldMap
impl Unpin for FoldMap
impl UnsafeUnpin for FoldMap
impl UnwindSafe for FoldMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.