diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs
index 8137e46583..fa0f173318 100644
--- a/crates/editor/src/display_map.rs
+++ b/crates/editor/src/display_map.rs
@@ -3,13 +3,12 @@ mod fold_map;
mod tab_map;
mod wrap_map;
-pub use block_map::{BlockDisposition, BlockId, BlockProperties, BufferRows, Chunks};
+pub use block_map::{
+ AlignedBlock, BlockContext, BlockDisposition, BlockId, BlockProperties, BufferRows, Chunks,
+};
use block_map::{BlockMap, BlockPoint};
use fold_map::{FoldMap, ToFoldPoint as _};
-use gpui::{
- fonts::{FontId, HighlightStyle},
- AppContext, Entity, ModelContext, ModelHandle,
-};
+use gpui::{fonts::FontId, ElementBox, Entity, ModelContext, ModelHandle};
use language::{Anchor, Buffer, Point, Subscription as BufferSubscription, ToOffset, ToPoint};
use std::{
collections::{HashMap, HashSet},
@@ -17,8 +16,7 @@ use std::{
};
use sum_tree::Bias;
use tab_map::TabMap;
-use text::Rope;
-use theme::{BlockStyle, SyntaxTheme};
+use theme::SyntaxTheme;
use wrap_map::WrapMap;
pub trait ToDisplayPoint {
@@ -124,14 +122,13 @@ impl DisplayMap {
self.block_map.read(snapshot, edits, cx);
}
- pub fn insert_blocks
(
+ pub fn insert_blocks
(
&mut self,
- blocks: impl IntoIterator- >,
+ blocks: impl IntoIterator
- >,
cx: &mut ModelContext,
) -> Vec
where
P: ToOffset + Clone,
- T: Into + Clone,
{
let snapshot = self.buffer.read(cx).snapshot();
let edits = self.buffer_subscription.consume().into_inner();
@@ -144,12 +141,11 @@ impl DisplayMap {
block_map.insert(blocks, cx)
}
- pub fn restyle_blocks(&mut self, styles: HashMap, Option)>)
+ pub fn replace_blocks(&mut self, styles: HashMap)
where
- F1: 'static + Fn(&AppContext) -> Vec<(usize, HighlightStyle)>,
- F2: 'static + Fn(&AppContext) -> BlockStyle,
+ F: 'static + Fn(&BlockContext) -> ElementBox,
{
- self.block_map.restyle(styles);
+ self.block_map.replace(styles);
}
pub fn remove_blocks(&mut self, ids: HashSet, cx: &mut ModelContext) {
@@ -198,8 +194,8 @@ impl DisplayMapSnapshot {
self.buffer_snapshot.len() == 0
}
- pub fn buffer_rows<'a>(&'a self, start_row: u32, cx: Option<&'a AppContext>) -> BufferRows<'a> {
- self.blocks_snapshot.buffer_rows(start_row, cx)
+ pub fn buffer_rows<'a>(&'a self, start_row: u32) -> BufferRows<'a> {
+ self.blocks_snapshot.buffer_rows(start_row)
}
pub fn buffer_row_count(&self) -> u32 {
@@ -256,7 +252,7 @@ impl DisplayMapSnapshot {
pub fn text_chunks(&self, display_row: u32) -> impl Iterator
- {
self.blocks_snapshot
- .chunks(display_row..self.max_point().row() + 1, None, None)
+ .chunks(display_row..self.max_point().row() + 1, None)
.map(|h| h.text)
}
@@ -264,9 +260,8 @@ impl DisplayMapSnapshot {
&'a self,
display_rows: Range,
theme: Option<&'a SyntaxTheme>,
- cx: &'a AppContext,
) -> block_map::Chunks<'a> {
- self.blocks_snapshot.chunks(display_rows, theme, Some(cx))
+ self.blocks_snapshot.chunks(display_rows, theme)
}
pub fn chars_at<'a>(&'a self, point: DisplayPoint) -> impl Iterator
- + 'a {
@@ -322,6 +317,13 @@ impl DisplayMapSnapshot {
self.folds_snapshot.folds_in_range(range)
}
+ pub fn blocks_in_range<'a>(
+ &'a self,
+ rows: Range,
+ ) -> impl Iterator
- {
+ self.blocks_snapshot.blocks_in_range(rows)
+ }
+
pub fn intersects_fold(&self, offset: T) -> bool {
self.folds_snapshot.intersects_fold(offset)
}
@@ -448,13 +450,6 @@ impl ToDisplayPoint for Anchor {
}
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum DisplayRow {
- Buffer(u32),
- Block(BlockId, Option),
- Wrap,
-}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -1065,7 +1060,7 @@ mod tests {
) -> Vec<(String, Option)> {
let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
let mut chunks: Vec<(String, Option)> = Vec::new();
- for chunk in snapshot.chunks(rows, Some(theme), cx) {
+ for chunk in snapshot.chunks(rows, Some(theme)) {
let color = chunk.highlight_style.map(|s| s.color);
if let Some((last_chunk, last_color)) = chunks.last_mut() {
if color == *last_color {
diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs
index 5ed1ac65fb..1cb5d961eb 100644
--- a/crates/editor/src/display_map/block_map.rs
+++ b/crates/editor/src/display_map/block_map.rs
@@ -1,26 +1,23 @@
-use super::{
- wrap_map::{self, Edit as WrapEdit, Snapshot as WrapSnapshot, WrapPoint},
- BlockStyle, DisplayRow,
-};
-use gpui::{fonts::HighlightStyle, AppContext, ModelHandle};
+use super::wrap_map::{self, Edit as WrapEdit, Snapshot as WrapSnapshot, WrapPoint};
+use gpui::{AppContext, ElementBox, ModelHandle};
use language::{Buffer, Chunk};
use parking_lot::Mutex;
use std::{
cmp::{self, Ordering},
collections::{HashMap, HashSet},
fmt::Debug,
- iter,
ops::{Deref, Range},
sync::{
atomic::{AtomicUsize, Ordering::SeqCst},
Arc,
},
- vec,
};
use sum_tree::SumTree;
-use text::{rope, Anchor, Bias, Edit, Point, Rope, ToOffset, ToPoint as _};
+use text::{Anchor, Bias, Edit, Point, ToOffset, ToPoint as _};
use theme::SyntaxTheme;
+const NEWLINES: &'static [u8] = &[b'\n'; u8::MAX as usize];
+
pub struct BlockMap {
buffer: ModelHandle,
next_block_id: AtomicUsize,
@@ -51,25 +48,28 @@ struct WrapRow(u32);
pub struct Block {
id: BlockId,
position: Anchor,
- text: Rope,
- build_runs: Mutex