pub struct DisplayMap { /* private fields */ }Expand description
DisplayMap is the main interface for Editor/Input coordinate mapping.
It manages the two-layer projection:
- Buffer → Wrap (soft-wrapping)
- Wrap → Display (folding)
Editor/Input only needs to work with BufferPoint and DisplayPoint.
Implementations§
Source§impl DisplayMap
impl DisplayMap
pub fn new( font: Font, font_size: Pixels, wrap_width: Option<Pixels>, ) -> DisplayMap
Sourcepub fn buffer_pos_to_display_pos(&self, pos: BufferPoint) -> DisplayPoint
pub fn buffer_pos_to_display_pos(&self, pos: BufferPoint) -> DisplayPoint
Convert buffer position to display position
Sourcepub fn display_pos_to_buffer_pos(&self, pos: DisplayPoint) -> BufferPoint
pub fn display_pos_to_buffer_pos(&self, pos: DisplayPoint) -> BufferPoint
Convert display position to buffer position
Sourcepub fn display_row_count(&self) -> usize
pub fn display_row_count(&self) -> usize
Get total number of visible display rows
Sourcepub fn display_row_to_buffer_line(&self, display_row: usize) -> usize
pub fn display_row_to_buffer_line(&self, display_row: usize) -> usize
Get the buffer line for a given display row
Sourcepub fn buffer_line_to_display_row_range(
&self,
line: usize,
) -> Option<Range<usize>>
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
Check if a buffer line is completely hidden
Sourcepub fn buffer_line_to_display_row(&self, line: usize) -> usize
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.
Sourcepub fn set_fold_candidates(&mut self, candidates: Vec<FoldRange>)
pub fn set_fold_candidates(&mut self, candidates: Vec<FoldRange>)
Set fold candidates (from tree-sitter/LSP)
Sourcepub fn set_folded(&mut self, start_line: usize, folded: bool)
pub fn set_folded(&mut self, start_line: usize, folded: bool)
Set a fold at the given start_line (must be in candidates)
Sourcepub fn toggle_fold(&mut self, start_line: usize)
pub fn toggle_fold(&mut self, start_line: usize)
Toggle fold at the given start_line
Sourcepub fn is_folded_at(&self, start_line: usize) -> bool
pub fn is_folded_at(&self, start_line: usize) -> bool
Check if a line is currently folded
Sourcepub fn is_fold_candidate(&self, start_line: usize) -> bool
pub fn is_fold_candidate(&self, start_line: usize) -> bool
Check if a line is a fold candidate
Sourcepub fn folded_ranges(&self) -> &[FoldRange]
pub fn folded_ranges(&self) -> &[FoldRange]
Get all currently folded ranges
Sourcepub fn clear_folds(&mut self)
pub fn clear_folds(&mut self)
Clear all folds
Sourcepub fn adjust_folds_for_edit(
&mut self,
old_text: &Rope,
range: &Range<usize>,
new_text: &str,
)
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.
Sourcepub 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,
)
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.
Sourcepub fn on_text_changed(
&mut self,
changed_text: &Rope,
range: &Range<usize>,
new_text: &Rope,
cx: &mut App,
)
pub fn on_text_changed( &mut self, changed_text: &Rope, range: &Range<usize>, new_text: &Rope, cx: &mut App, )
Update text (incremental or full)
Sourcepub fn on_layout_changed(&mut self, wrap_width: Option<Pixels>, cx: &mut App)
pub fn on_layout_changed(&mut self, wrap_width: Option<Pixels>, cx: &mut App)
Update layout parameters (wrap width or font)
Sourcepub fn set_wrapping_indent(
&mut self,
wrapping_indent: WrappingIndent,
cx: &mut App,
)
pub fn set_wrapping_indent( &mut self, wrapping_indent: WrappingIndent, cx: &mut App, )
Set the wrapping indent for continuation lines.
Sourcepub fn ensure_text_prepared(&mut self, text: &Rope, cx: &mut App)
pub fn ensure_text_prepared(&mut self, text: &Rope, cx: &mut App)
Ensure text is prepared (initializes wrapper if needed)
Sourcepub fn wrap_row_to_display_row(&self, wrap_row: usize) -> Option<usize>
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.
Sourcepub fn nearest_visible_display_row(&self, wrap_row: usize) -> usize
pub fn nearest_visible_display_row(&self, wrap_row: usize) -> usize
Find the nearest visible display row for a given wrap row.
Sourcepub fn display_row_to_wrap_row(&self, display_row: usize) -> Option<usize>
pub fn display_row_to_wrap_row(&self, display_row: usize) -> Option<usize>
Convert a display row to a wrap row.
Sourcepub fn visible_wrap_row_count_for_buffer_line(&self, line: usize) -> usize
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)
Sourcepub fn wrap_row_count(&self) -> usize
pub fn wrap_row_count(&self) -> usize
Get the wrap row count (before folding)
Sourcepub fn buffer_line_count(&self) -> usize
pub fn buffer_line_count(&self) -> usize
Get the buffer line count (logical lines)
Auto Trait Implementations§
impl Freeze for DisplayMap
impl RefUnwindSafe for DisplayMap
impl Send for DisplayMap
impl Sync for DisplayMap
impl Unpin for DisplayMap
impl UnsafeUnpin for DisplayMap
impl UnwindSafe for DisplayMap
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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