Skip to main content

TabMap

Struct TabMap 

Source
pub struct TabMap<'a> { /* private fields */ }
Expand description

The coordinates seam — a concrete type, not a trait.

Its entire durable state is tab_size; it holds no persisted visual indices, so there is nothing derived that could drift out of sync with the text. Built per frame from the document’s tab_size plus a borrow of the buffer’s line index, so every conversion reads live text and the map is current by construction.

Every method that can land on a lossy position (mid-tab, or inside a fold at the layer above) threads Bias from the start, so no call site needs retrofitting when a new lossy case appears.

Implementations§

Source§

impl<'a> TabMap<'a>

Source

pub fn new(lines: &'a Buffer, tab_size: u32) -> Self

A map over lines with the given tab stop width. tab_size is expected to be ≥ 1 (see default_tab_size).

Source

pub fn to_display(&self, point: Point, _bias: Bias) -> DisplayPoint

Buffer → display. point.col is a char-boundary byte column (the buffer guarantees this); the result column is cells. Total: every valid buffer point maps to exactly one display point, so bias is irrelevant here.

Source

pub fn to_buffer(&self, point: DisplayPoint, bias: Bias) -> Point

Display → buffer, with the bias snap: if point.col falls strictly inside a tab expansion it is not a caret slot — Left yields the byte of the \t, Right the byte after it.

Source

pub fn clip(&self, point: DisplayPoint, bias: Bias) -> DisplayPoint

Snap any externally-sourced display position (mouse hit, diagnostic span, find match) to the nearest valid caret slot — the guard every such position passes before use. Steps: collapse by bias → clamp + char snap in buffer space → re-expand. Idempotent.

Source

pub fn max_point(&self) -> DisplayPoint

The bottom-right valid position: the last row and its cell length.

Source

pub fn row_count(&self) -> u32

Number of display rows in this map — the buffer line count. (Hiding rows is the FoldMap layer’s job, above this one.)

Source

pub fn line_len(&self, row: DisplayRow) -> u32

Cell width of a display row (the whole line expanded).

Source

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

Gutter protocol: the buffer line number to print. Always Some in this map; the Option lets a caller handle a display row that has no printed line number.

Source

pub fn sync(&mut self, _buffer_patch: &Patch)

Consume the transaction’s buffer-space edit patch and splice any internal derived state. Returns (): downstream caches (line cache, paragraph cache) invalidate off the buffer-space LineSplice they already consume, so no display-space edit vector is emitted — widen to Vec<DisplayEdit> only if a display-space reader ever appears. The map holds no derived state, so this is a no-op; the borrow of live buffer text keeps every conversion current by construction.

Source

pub fn max_row(&self) -> DisplayRow

The last display row. row_count − 1, saturating.

Auto Trait Implementations§

§

impl<'a> Freeze for TabMap<'a>

§

impl<'a> RefUnwindSafe for TabMap<'a>

§

impl<'a> Send for TabMap<'a>

§

impl<'a> Sync for TabMap<'a>

§

impl<'a> Unpin for TabMap<'a>

§

impl<'a> UnsafeUnpin for TabMap<'a>

§

impl<'a> UnwindSafe for TabMap<'a>

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