Skip to main content

DisplayMap

Struct DisplayMap 

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

DisplayMap is the main interface for Editor/Input coordinate mapping.

It manages the two-layer projection:

  1. Buffer → Wrap (soft-wrapping)
  2. Wrap → Display (folding)

Editor/Input only needs to work with BufferPoint and DisplayPoint.

Implementations§

Source§

impl DisplayMap

Source

pub fn new(font: Font, font_size: Pixels, wrap_width: Option<Pixels>) -> Self

Source

pub fn buffer_pos_to_display_pos(&self, pos: BufferPoint) -> DisplayPoint

Convert buffer position to display position

Source

pub fn display_pos_to_buffer_pos(&self, pos: DisplayPoint) -> BufferPoint

Convert display position to buffer position

Source

pub fn display_row_count(&self) -> usize

Get total number of visible display rows

Source

pub fn display_row_to_buffer_line(&self, display_row: usize) -> usize

Get the buffer line for a given display row

Source

pub fn buffer_line_to_display_row_range( &self, line: usize, ) -> Option<Range<usize>>

Get the display row range for a buffer line: [start, end) Returns None if the buffer line is completely hidden

Source

pub fn is_buffer_line_hidden(&self, line: usize) -> bool

Check if a buffer line is completely hidden

Source

pub fn buffer_line_to_display_row(&self, line: usize) -> usize

First display row of a buffer line. If the line is fully folded, returns the nearest visible display row.

Source

pub fn set_fold_candidates(&mut self, candidates: Vec<FoldRange>)

Set fold candidates (from tree-sitter/LSP)

Source

pub fn set_folded(&mut self, start_line: usize, folded: bool)

Set a fold at the given start_line (must be in candidates)

Source

pub fn toggle_fold(&mut self, start_line: usize)

Toggle fold at the given start_line

Source

pub fn is_folded_at(&self, start_line: usize) -> bool

Check if a line is currently folded

Source

pub fn is_fold_candidate(&self, start_line: usize) -> bool

Check if a line is a fold candidate

Source

pub fn folded_ranges(&self) -> &[FoldRange]

Get all currently folded ranges

Source

pub fn clear_folds(&mut self)

Clear all folds

Source

pub fn adjust_folds_for_edit( &mut self, old_text: &Rope, range: &Range<usize>, new_text: &str, )

Adjust folds and candidates for a text edit before updating the wrap map.

Must be called with the OLD text (before replacement) and the edit range/new_text so we can compute which old lines were affected.

Source

pub fn update_fold_candidates_for_edit( &mut self, extract_fold_ranges: impl FnOnce(Range<usize>, &Rope) -> Vec<FoldRange>, edit_byte_range: Range<usize>, new_text: &Rope, )

Incrementally update fold candidates after a text edit.

Extracts new fold candidates only within the edited byte range and merges them with existing (already adjusted) candidates.

Source

pub fn on_text_changed( &mut self, changed_text: &Rope, range: &Range<usize>, new_text: &Rope, cx: &mut App, )

Update text (incremental or full)

Source

pub fn on_layout_changed(&mut self, wrap_width: Option<Pixels>, cx: &mut App)

Update layout parameters (wrap width or font)

Source

pub fn set_wrapping_indent( &mut self, wrapping_indent: WrappingIndent, cx: &mut App, )

Set the wrapping indent for continuation lines.

Source

pub fn set_font(&mut self, font: Font, font_size: Pixels, cx: &mut App)

Set font parameters

Source

pub fn ensure_text_prepared(&mut self, text: &Rope, cx: &mut App)

Ensure text is prepared (initializes wrapper if needed)

Source

pub fn set_text(&mut self, text: &Rope, cx: &mut App)

Initialize with text

Source

pub fn wrap_row_to_display_row(&self, wrap_row: usize) -> Option<usize>

Convert a wrap row to a display row (skipping folded rows). Returns None if the wrap row is folded.

Source

pub fn nearest_visible_display_row(&self, wrap_row: usize) -> usize

Find the nearest visible display row for a given wrap row.

Source

pub fn display_row_to_wrap_row(&self, display_row: usize) -> Option<usize>

Convert a display row to a wrap row.

Source

pub fn text(&self) -> &Rope

Get the rope text

Source

pub fn visible_wrap_row_count_for_buffer_line(&self, line: usize) -> usize

Calculate how many wrap rows of a buffer line are visible (not folded)

Source

pub fn wrap_row_count(&self) -> usize

Get the wrap row count (before folding)

Source

pub fn buffer_line_count(&self) -> usize

Get the buffer line count (logical lines)

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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