diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 7ab5b0ff2abe75b6a35ab2ed120c2dee55e489af..7f29a7d04f536ac8de4af01cf2368e7be948b054 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -1,3 +1,22 @@ +//! This module defines where the text should be displayed in an [`Editor`][Editor]. +//! +//! Not literally though - rendering, layout and all that jazz is a responsibility of [`EditorElement`][EditorElement]. +//! Instead, [`DisplayMap`] decides where Inlays/Inlay hints are displayed, when +//! to apply a soft wrap, where to add fold indicators, whether there are any tabs in the buffer that +//! we display as spaces and where to display custom blocks (like diagnostics). +//! Seems like a lot? That's because it is. [`DisplayMap`] is conceptually made up +//! of several smaller structures that form a hierarchy (starting at the bottom): +//! - [`InlayMap`] that decides where the [`Inlay`]s should be displayed. +//! - [`FoldMap`] that decides where the fold indicators should be; it also tracks parts of a source file that are currently folded. +//! - [`TabMap`] that keeps track of hard tabs in a buffer. +//! - [`WrapMap`] that handles soft wrapping. +//! - [`BlockMap`] that tracks custom blocks such as diagnostics that should be displayed within buffer. +//! - [`DisplayMap`] that adds background highlights to the regions of text. +//! Each one of those builds on top of preceding map. +//! +//! [Editor]: crate::Editor +//! [EditorElement]: crate::element::EditorElement + mod block_map; mod fold_map; mod inlay_map; @@ -971,24 +990,6 @@ impl ToDisplayPoint for Anchor { } } -pub fn next_rows(display_row: u32, display_map: &DisplaySnapshot) -> impl Iterator { - let max_row = display_map.max_point().row(); - let start_row = display_row + 1; - let mut current = None; - std::iter::from_fn(move || { - if current == None { - current = Some(start_row); - } else { - current = Some(current.unwrap() + 1) - } - if current.unwrap() > max_row { - None - } else { - current - } - }) -} - #[cfg(test)] pub mod tests { use super::*; diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 7c6eeb444eb69ca7557a6d55ab4b4b1125b8b078..61b973cc6c70cd8ff733753c23f22474f58fce82 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -71,10 +71,10 @@ impl<'a> sum_tree::Dimension<'a, TransformSummary> for FoldPoint { } } -pub struct FoldMapWriter<'a>(&'a mut FoldMap); +pub(crate) struct FoldMapWriter<'a>(&'a mut FoldMap); impl<'a> FoldMapWriter<'a> { - pub fn fold( + pub(crate) fn fold( &mut self, ranges: impl IntoIterator>, ) -> (FoldSnapshot, Vec) { @@ -129,7 +129,7 @@ impl<'a> FoldMapWriter<'a> { (self.0.snapshot.clone(), edits) } - pub fn unfold( + pub(crate) fn unfold( &mut self, ranges: impl IntoIterator>, inclusive: bool, @@ -178,14 +178,14 @@ impl<'a> FoldMapWriter<'a> { } } -pub struct FoldMap { +pub(crate) struct FoldMap { snapshot: FoldSnapshot, ellipses_color: Option, next_fold_id: FoldId, } impl FoldMap { - pub fn new(inlay_snapshot: InlaySnapshot) -> (Self, FoldSnapshot) { + pub(crate) fn new(inlay_snapshot: InlaySnapshot) -> (Self, FoldSnapshot) { let this = Self { snapshot: FoldSnapshot { folds: Default::default(),