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 three-layer projection:

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

crate::input::InputBaseState::display_map exposes the editor-owned map through a shared reference for application coordinate queries. Text edits, wrapping, and folding remain owned by the editor state.

Coordinates describe the prepared text projection, including offscreen lines. They exclude inline completion ghost lines and other painted geometry.

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

A spacer row is read as the nearest row of the line it stands beside.

Source

pub fn version(&self) -> usize

A number that changes whenever a buffer line may have taken different display rows: an edit, a rewrap, a change of folds or of spacers.

Compare versions for equality on the same map to invalidate cached queries. The counter can wrap; it is not a document revision or a count of edits. Scrolling and inline completion ghost lines do not change it, nor does a crate::input::SpacerProvider answering with the spacers already shown.

Source

pub fn display_row_count(&self) -> usize

Get total number of visible display rows, spacer rows included

Source

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

Get the buffer line for a given display row

A spacer row belongs to the line it stands beside.

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

The range holds the rows of the line’s text, not its spacers.

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 is_spacer_row(&self, display_row: usize) -> bool

Whether a display row is a spacer row: a blank row that holds no text, standing above or below a line. See Spacer.

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 on the lines of 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)

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. Returns None for a spacer 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§

§

impl !RefUnwindSafe for DisplayMap

§

impl !Send for DisplayMap

§

impl !Sync for DisplayMap

§

impl !UnwindSafe for DisplayMap

§

impl Forget for DisplayMap

§

impl Freeze for DisplayMap
where *const ArcInner<Children> is !null: Freeze, PhantomData<ArcInner<Children>>: Freeze, *const ArcInner<Text> is !null: Freeze, PhantomData<ArcInner<Text>>: Freeze, &'static str: Freeze, *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, *const ArcInner<Vec<(String, u32)>> is !null: Freeze, PhantomData<ArcInner<Vec<(String, u32)>>>: Freeze, *const ArcInner<Vec<String>> is !null: Freeze, PhantomData<ArcInner<Vec<String>>>: Freeze, *const ArcInner<Node<LineItem>> is !null: Freeze, PhantomData<ArcInner<Node<LineItem>>>: Freeze, *const RcInner<[(Range<usize>, Pixels)]> is !null: Freeze, PhantomData<RcInner<[(Range<usize>, Pixels)]>>: Freeze, *const RcInner<[FontSpan]> is !null: Freeze, PhantomData<RcInner<[FontSpan]>>: Freeze, *const RcInner<RefCell<WidthMeasurements>> is !null: Freeze, PhantomData<RcInner<RefCell<WidthMeasurements>>>: Freeze, *const RcInner<MonospaceWidths> is !null: Freeze, PhantomData<RcInner<MonospaceWidths>>: Freeze, *const u8 is !null: Freeze, PhantomData<usize>: Freeze, PhantomData<(char, Option<f64>)>: Freeze, PhantomData<(u64, bool)>: Freeze, PhantomData<f64>: Freeze, PhantomData<char>: Freeze, PhantomData<HiddenRows>: Freeze, PhantomData<FoldRange>: Freeze, PhantomData<SpacerRows>: Freeze, PhantomData<Spacer>: Freeze,

§

impl Move for DisplayMap

§

impl Unpin for DisplayMap
where Arc<Children>: Unpin, Arc<Text>: Unpin, &'static str: Unpin, Arc<str>: Unpin, Arc<Vec<(String, u32)>>: Unpin, Arc<Vec<String>>: Unpin, Arc<Node<LineItem>>: Unpin, Rc<[(Range<usize>, Pixels)]>: Unpin, Rc<[FontSpan]>: Unpin, Rc<RefCell<WidthMeasurements>>: Unpin, Rc<MonospaceWidths>: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for DisplayMap
where *const ArcInner<Children> is !null: UnsafeUnpin, PhantomData<ArcInner<Children>>: UnsafeUnpin, *const ArcInner<Text> is !null: UnsafeUnpin, PhantomData<ArcInner<Text>>: UnsafeUnpin, &'static str: UnsafeUnpin, *const ArcInner<str> is !null: UnsafeUnpin, PhantomData<ArcInner<str>>: UnsafeUnpin, *const ArcInner<Vec<(String, u32)>> is !null: UnsafeUnpin, PhantomData<ArcInner<Vec<(String, u32)>>>: UnsafeUnpin, *const ArcInner<Vec<String>> is !null: UnsafeUnpin, PhantomData<ArcInner<Vec<String>>>: UnsafeUnpin, *const ArcInner<Node<LineItem>> is !null: UnsafeUnpin, PhantomData<ArcInner<Node<LineItem>>>: UnsafeUnpin, *const RcInner<[(Range<usize>, Pixels)]> is !null: UnsafeUnpin, PhantomData<RcInner<[(Range<usize>, Pixels)]>>: UnsafeUnpin, *const RcInner<[FontSpan]> is !null: UnsafeUnpin, PhantomData<RcInner<[FontSpan]>>: UnsafeUnpin, *const RcInner<RefCell<WidthMeasurements>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<WidthMeasurements>>>: UnsafeUnpin, *const RcInner<MonospaceWidths> is !null: UnsafeUnpin, PhantomData<RcInner<MonospaceWidths>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, PhantomData<(char, Option<f64>)>: UnsafeUnpin, PhantomData<(u64, bool)>: UnsafeUnpin, PhantomData<f64>: UnsafeUnpin, PhantomData<char>: UnsafeUnpin, PhantomData<HiddenRows>: UnsafeUnpin, PhantomData<FoldRange>: UnsafeUnpin, PhantomData<SpacerRows>: UnsafeUnpin, PhantomData<Spacer>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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