Skip to main content

CellMatrix

Struct CellMatrix 

Source
pub struct CellMatrix {
    pub chunks: Arc<[Arc<CellChunk>]>,
    pub chunk_size: u32,
    pub source_line_count: u32,
    pub visible_line_count: u32,
    pub version: MatrixVersion,
    pub wrap_width: u32,
}
Expand description

The published cell matrix for a single buffer.

Immutable once built; cell-builder replaces the published Arc when versions change. Cheap to clone (Arc bump).

Fields§

§chunks: Arc<[Arc<CellChunk>]>

Chunks ordered by start_source_line. Whole-doc mode has exactly one chunk.

§chunk_size: u32

Logical lines per chunk, or CHUNK_SIZE_WHOLE_DOC for whole-doc mode.

§source_line_count: u32

Total logical lines in the source buffer (pre-fold).

§visible_line_count: u32

Total matrix rows across all chunks (post-fold).

§version: MatrixVersion

Component-wise maximum of all chunks’ captured versions.

§wrap_width: u32

Soft-wrap (W.2, A2): the column width each source line is wrapped at when :set wrap is on, or 0 when wrapping is off (the historical default — every source line is exactly one display row). The cells worker stamps this from the pane’s viewport_width; consumers derive display geometry via Self::segment_count without the matrix storing per-line segment data. One CellRow per source line is preserved either way — see docs/dev/architecture/soft-wrap.md (A2).

Implementations§

Source§

impl CellMatrix

Source

pub fn empty() -> Self

Empty matrix: no chunks, no rows. The initial published value before the cell-builder finishes its first build.

Source

pub fn chunked( chunks: impl Into<Arc<[Arc<CellChunk>]>>, chunk_size: u32, source_line_count: u32, version: MatrixVersion, ) -> Self

Construct a matrix in chunked mode. S2 is the production caller; chunk_size must be > 0. Use Self::whole_doc for the single-chunk mode.

version is the aggregate stamp the renderer can inspect to detect “is this matrix newer than the one I painted last frame?” Comparison is != (see MatrixVersion::differs_from) because some axes are hash-style and don’t admit ordering. Production builds pass the publisher’s current MatrixVersion snapshot; defaults to all-zero for empty / test cases.

Source

pub fn whole_doc(chunk: Arc<CellChunk>, source_line_count: u32) -> Self

Construct a matrix in whole-doc mode (one chunk).

Source

pub fn is_whole_doc(&self) -> bool

true when running in whole-doc mode (one chunk covering the entire document).

Source

pub fn is_empty(&self) -> bool

true when no chunks/rows are present.

Source

pub fn segment_count(&self, target: u32) -> u32

Soft-wrap (W.2, A2): how many display rows the source line target occupies. 1 when wrapping is off (wrap_width == 0) or the line is missing/folded; otherwise ⌈col_count / wrap_width⌉, floored at 1 (an empty line still occupies one display row).

This is the published geometry the host scroll model (bottom_anchored_scroll) and both renderers read to expand a source line into wrap segments — no per-line segment data is stored on the matrix.

Source

pub fn row_at_source_line(&self, target: u32) -> Option<&CellRow>

S3.c.0 (2026-05-26): look up the row whose logical source line equals target. Returns None when the target line is folded (no visible row) or past the matrix’s coverage.

Walks chunks linearly; chunks are sorted by start_source_line. Most callers ask for visible lines (≤ viewport_height per frame); a typical 100K-line buffer at chunk_size = 128 has ~780 chunks, so the walk is sub-µs even without an outer binary search.

Source

pub fn covered_start_line(&self) -> u32

H.3 (2026-06-04): first source line this matrix’s chunks were built to cover. 0 for whole-doc mode and full-coverage chunked mode; the window’s lower bound for a windowed large-file matrix. Derived from the first chunk’s start_source_line (exact — chunks are ordered).

Source

pub fn covered_end_line(&self) -> u32

H.3: exclusive upper bound of the source-line range this matrix’s chunks were built to cover. source_line_count in whole-doc mode; otherwise the last chunk’s start_source_line + chunk_size, clamped to source_line_count. Robust against fold elision (a fully folded tail chunk still reports the source span it was built over) and against a window that ends mid-chunk_size (build_matrix aligns the window up to chunk_size, so the last chunk’s nominal end equals the window’s upper bound).

Source

pub fn covers(&self, lo: u32, hi: u32) -> bool

H.3: does this matrix cover the entire source-line range [lo, hi)? The cells worker’s cache-hit gate uses this to keep a windowed large-file matrix from serving a viewport that has scrolled past its covered range — when it returns false, the worker rebuilds the window around the new scroll. An empty matrix (no chunks) covers nothing.

Source

pub fn slice(&self, scroll: u32, height: u32) -> CellSlice<'_>

Borrow the visible rows starting at matrix-row index scroll, up to height rows. Returns a CellSlice that iterates &CellRow references without allocating.

If scroll + height exceeds visible_line_count, the slice is naturally truncated (no panic, no padding). The renderer must paint blank rows below the slice’s end when the viewport extends past EOF.

Source

pub fn display_slice<'a>( &'a self, scroll: u32, height: u32, virtual_rows: &'a VirtualRowMatrix, ) -> DisplaySlice<'a>

D.0a: borrow height display rows starting at display row scroll, interleaving virtual rows from virtual_rows with the document rows in this matrix.

scroll and height are in display-row space — they count both document rows and virtual rows. Returns a DisplaySlice that iterates DisplayRowEntry::Document for document rows and DisplayRowEntry::Virtual for virtual rows in natural top-to-bottom order.

When virtual_rows.is_empty() the iterator degenerates to the same yield order as Self::slice; renderers can call display_slice unconditionally without paying for the interleaver when no provider has registered virtual rows.

See docs/dev/architecture/virtual-rows.md for the full ordering contract (Above-before-Cell-before-Below at each anchor line, folded-line anchors emit at the next visible line, past-EOF anchors emit at the end).

Trait Implementations§

Source§

impl Clone for CellMatrix

Source§

fn clone(&self) -> CellMatrix

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 CellMatrix

Source§

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

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

impl Default for CellMatrix

Source§

fn default() -> Self

Equivalent to Self::empty. Provided so containers like Arc<ArcSwap<CellMatrix>> derive Default without explicit-init plumbing at every call site.

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more