diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 9167356795..fc871c9862 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -3,9 +3,6 @@ mod fold_map; mod tab_map; mod wrap_map; -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, ElementBox, Entity, ModelContext, ModelHandle}; @@ -19,8 +16,13 @@ use tab_map::TabMap; use theme::SyntaxTheme; use wrap_map::WrapMap; +pub use block_map::{ + AlignedBlock, BlockBufferRows as DisplayBufferRows, BlockChunks as DisplayChunks, BlockContext, + BlockDisposition, BlockId, BlockProperties, +}; + pub trait ToDisplayPoint { - fn to_display_point(&self, map: &DisplayMapSnapshot) -> DisplayPoint; + fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint; } pub struct DisplayMap { @@ -61,7 +63,7 @@ impl DisplayMap { } } - pub fn snapshot(&self, cx: &mut ModelContext) -> DisplayMapSnapshot { + pub fn snapshot(&self, cx: &mut ModelContext) -> DisplaySnapshot { let buffer_snapshot = self.buffer.read(cx).snapshot(); let edits = self.buffer_subscription.consume().into_inner(); let (folds_snapshot, edits) = self.fold_map.read(buffer_snapshot, edits); @@ -71,7 +73,7 @@ impl DisplayMap { .update(cx, |map, cx| map.sync(tabs_snapshot.clone(), edits, cx)); let blocks_snapshot = self.block_map.read(wraps_snapshot.clone(), edits, cx); - DisplayMapSnapshot { + DisplaySnapshot { buffer_snapshot: self.buffer.read(cx).snapshot(), folds_snapshot, tabs_snapshot, @@ -176,15 +178,15 @@ impl DisplayMap { } } -pub struct DisplayMapSnapshot { - pub buffer_snapshot: language::Snapshot, - folds_snapshot: fold_map::Snapshot, - tabs_snapshot: tab_map::Snapshot, - wraps_snapshot: wrap_map::Snapshot, +pub struct DisplaySnapshot { + pub buffer_snapshot: language::BufferSnapshot, + folds_snapshot: fold_map::FoldSnapshot, + tabs_snapshot: tab_map::TabSnapshot, + wraps_snapshot: wrap_map::WrapSnapshot, blocks_snapshot: block_map::BlockSnapshot, } -impl DisplayMapSnapshot { +impl DisplaySnapshot { #[cfg(test)] pub fn fold_count(&self) -> usize { self.folds_snapshot.fold_count() @@ -194,7 +196,7 @@ impl DisplayMapSnapshot { self.buffer_snapshot.len() == 0 } - pub fn buffer_rows<'a>(&'a self, start_row: u32) -> BufferRows<'a> { + pub fn buffer_rows<'a>(&'a self, start_row: u32) -> DisplayBufferRows<'a> { self.blocks_snapshot.buffer_rows(start_row) } @@ -260,7 +262,7 @@ impl DisplayMapSnapshot { &'a self, display_rows: Range, theme: Option<&'a SyntaxTheme>, - ) -> block_map::Chunks<'a> { + ) -> DisplayChunks<'a> { self.blocks_snapshot.chunks(display_rows, theme) } @@ -420,11 +422,11 @@ impl DisplayPoint { &mut self.0.column } - pub fn to_point(self, map: &DisplayMapSnapshot) -> Point { + pub fn to_point(self, map: &DisplaySnapshot) -> Point { map.display_point_to_point(self, Bias::Left) } - pub fn to_offset(self, map: &DisplayMapSnapshot, bias: Bias) -> usize { + pub fn to_offset(self, map: &DisplaySnapshot, bias: Bias) -> usize { let unblocked_point = map.blocks_snapshot.to_wrap_point(self.0); let unwrapped_point = map.wraps_snapshot.to_tab_point(unblocked_point); let unexpanded_point = map.tabs_snapshot.to_fold_point(unwrapped_point, bias).0; @@ -433,19 +435,19 @@ impl DisplayPoint { } impl ToDisplayPoint for usize { - fn to_display_point(&self, map: &DisplayMapSnapshot) -> DisplayPoint { + fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint { map.point_to_display_point(self.to_point(&map.buffer_snapshot), Bias::Left) } } impl ToDisplayPoint for Point { - fn to_display_point(&self, map: &DisplayMapSnapshot) -> DisplayPoint { + fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint { map.point_to_display_point(*self, Bias::Left) } } impl ToDisplayPoint for Anchor { - fn to_display_point(&self, map: &DisplayMapSnapshot) -> DisplayPoint { + fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint { self.to_point(&map.buffer_snapshot).to_display_point(map) } } diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index 58ae22403d..02cbc0ab32 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -1,4 +1,4 @@ -use super::wrap_map::{self, Edit as WrapEdit, Snapshot as WrapSnapshot, WrapPoint}; +use super::wrap_map::{self, Edit as WrapEdit, WrapPoint, WrapSnapshot}; use gpui::{AppContext, ElementBox, ModelHandle}; use language::{Buffer, Chunk}; use parking_lot::Mutex; @@ -93,17 +93,17 @@ struct TransformSummary { output_rows: u32, } -pub struct Chunks<'a> { +pub struct BlockChunks<'a> { transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>, - input_chunks: wrap_map::Chunks<'a>, + input_chunks: wrap_map::WrapChunks<'a>, input_chunk: Chunk<'a>, output_row: u32, max_output_row: u32, } -pub struct BufferRows<'a> { +pub struct BlockBufferRows<'a> { transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>, - input_buffer_rows: wrap_map::BufferRows<'a>, + input_buffer_rows: wrap_map::WrapBufferRows<'a>, output_row: u32, started: bool, } @@ -476,7 +476,11 @@ impl BlockSnapshot { .collect() } - pub fn chunks<'a>(&'a self, rows: Range, theme: Option<&'a SyntaxTheme>) -> Chunks<'a> { + pub fn chunks<'a>( + &'a self, + rows: Range, + theme: Option<&'a SyntaxTheme>, + ) -> BlockChunks<'a> { let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows); let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(); let input_end = { @@ -503,7 +507,7 @@ impl BlockSnapshot { }; cursor.start().1 .0 + overshoot }; - Chunks { + BlockChunks { input_chunks: self.wrap_snapshot.chunks(input_start..input_end, theme), input_chunk: Default::default(), transforms: cursor, @@ -512,7 +516,7 @@ impl BlockSnapshot { } } - pub fn buffer_rows<'a>(&'a self, start_row: u32) -> BufferRows<'a> { + pub fn buffer_rows<'a>(&'a self, start_row: u32) -> BlockBufferRows<'a> { let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(); cursor.seek(&BlockRow(start_row), Bias::Right, &()); let (output_start, input_start) = cursor.start(); @@ -522,7 +526,7 @@ impl BlockSnapshot { 0 }; let input_start_row = input_start.0 + overshoot; - BufferRows { + BlockBufferRows { transforms: cursor, input_buffer_rows: self.wrap_snapshot.buffer_rows(input_start_row), output_row: start_row, @@ -693,7 +697,7 @@ impl Transform { } } -impl<'a> Iterator for Chunks<'a> { +impl<'a> Iterator for BlockChunks<'a> { type Item = Chunk<'a>; fn next(&mut self) -> Option { @@ -756,7 +760,7 @@ impl<'a> Iterator for Chunks<'a> { } } -impl<'a> Iterator for BufferRows<'a> { +impl<'a> Iterator for BlockBufferRows<'a> { type Item = Option; fn next(&mut self) -> Option { diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 31edebe99c..1f8f710ce1 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -1,6 +1,5 @@ use language::{ - Anchor, AnchorRangeExt, Chunk, Edit, Point, PointUtf16, Snapshot as BufferSnapshot, - TextSummary, ToOffset, + Anchor, AnchorRangeExt, BufferSnapshot, Chunk, Edit, Point, PointUtf16, TextSummary, ToOffset, }; use parking_lot::Mutex; use std::{ @@ -13,7 +12,7 @@ use sum_tree::{Bias, Cursor, FilterCursor, SumTree}; use theme::SyntaxTheme; pub trait ToFoldPoint { - fn to_fold_point(&self, snapshot: &Snapshot, bias: Bias) -> FoldPoint; + fn to_fold_point(&self, snapshot: &FoldSnapshot, bias: Bias) -> FoldPoint; } #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] @@ -41,14 +40,14 @@ impl FoldPoint { &mut self.0.column } - pub fn to_buffer_point(&self, snapshot: &Snapshot) -> Point { + pub fn to_buffer_point(&self, snapshot: &FoldSnapshot) -> Point { let mut cursor = snapshot.transforms.cursor::<(FoldPoint, Point)>(); cursor.seek(self, Bias::Right, &()); let overshoot = self.0 - cursor.start().0 .0; cursor.start().1 + overshoot } - pub fn to_buffer_offset(&self, snapshot: &Snapshot) -> usize { + pub fn to_buffer_offset(&self, snapshot: &FoldSnapshot) -> usize { let mut cursor = snapshot.transforms.cursor::<(FoldPoint, Point)>(); cursor.seek(self, Bias::Right, &()); let overshoot = self.0 - cursor.start().0 .0; @@ -57,7 +56,7 @@ impl FoldPoint { .to_offset(cursor.start().1 + overshoot) } - pub fn to_offset(&self, snapshot: &Snapshot) -> FoldOffset { + pub fn to_offset(&self, snapshot: &FoldSnapshot) -> FoldOffset { let mut cursor = snapshot .transforms .cursor::<(FoldPoint, TransformSummary)>(); @@ -77,7 +76,7 @@ impl FoldPoint { } impl ToFoldPoint for Point { - fn to_fold_point(&self, snapshot: &Snapshot, bias: Bias) -> FoldPoint { + fn to_fold_point(&self, snapshot: &FoldSnapshot, bias: Bias) -> FoldPoint { let mut cursor = snapshot.transforms.cursor::<(Point, FoldPoint)>(); cursor.seek(self, Bias::Right, &()); if cursor.item().map_or(false, |t| t.is_fold()) { @@ -102,7 +101,7 @@ impl<'a> FoldMapWriter<'a> { pub fn fold( &mut self, ranges: impl IntoIterator>, - ) -> (Snapshot, Vec) { + ) -> (FoldSnapshot, Vec) { let mut edits = Vec::new(); let mut folds = Vec::new(); let buffer = self.0.buffer.lock().clone(); @@ -133,7 +132,7 @@ impl<'a> FoldMapWriter<'a> { consolidate_buffer_edits(&mut edits); let edits = self.0.sync(buffer.clone(), edits); - let snapshot = Snapshot { + let snapshot = FoldSnapshot { transforms: self.0.transforms.lock().clone(), folds: self.0.folds.clone(), buffer_snapshot: buffer, @@ -145,7 +144,7 @@ impl<'a> FoldMapWriter<'a> { pub fn unfold( &mut self, ranges: impl IntoIterator>, - ) -> (Snapshot, Vec) { + ) -> (FoldSnapshot, Vec) { let mut edits = Vec::new(); let mut fold_ixs_to_delete = Vec::new(); let buffer = self.0.buffer.lock().clone(); @@ -179,7 +178,7 @@ impl<'a> FoldMapWriter<'a> { consolidate_buffer_edits(&mut edits); let edits = self.0.sync(buffer.clone(), edits); - let snapshot = Snapshot { + let snapshot = FoldSnapshot { transforms: self.0.transforms.lock().clone(), folds: self.0.folds.clone(), buffer_snapshot: buffer, @@ -197,7 +196,7 @@ pub struct FoldMap { } impl FoldMap { - pub fn new(buffer: BufferSnapshot) -> (Self, Snapshot) { + pub fn new(buffer: BufferSnapshot) -> (Self, FoldSnapshot) { let this = Self { buffer: Mutex::new(buffer.clone()), folds: Default::default(), @@ -214,7 +213,7 @@ impl FoldMap { version: Default::default(), }; - let snapshot = Snapshot { + let snapshot = FoldSnapshot { transforms: this.transforms.lock().clone(), folds: this.folds.clone(), buffer_snapshot: this.buffer.lock().clone(), @@ -227,10 +226,10 @@ impl FoldMap { &self, buffer: BufferSnapshot, edits: Vec>, - ) -> (Snapshot, Vec) { + ) -> (FoldSnapshot, Vec) { let edits = self.sync(buffer, edits); self.check_invariants(); - let snapshot = Snapshot { + let snapshot = FoldSnapshot { transforms: self.transforms.lock().clone(), folds: self.folds.clone(), buffer_snapshot: self.buffer.lock().clone(), @@ -243,7 +242,7 @@ impl FoldMap { &mut self, buffer: BufferSnapshot, edits: Vec>, - ) -> (FoldMapWriter, Snapshot, Vec) { + ) -> (FoldMapWriter, FoldSnapshot, Vec) { let (snapshot, edits) = self.read(buffer, edits); (FoldMapWriter(self), snapshot, edits) } @@ -474,14 +473,14 @@ impl FoldMap { } #[derive(Clone)] -pub struct Snapshot { +pub struct FoldSnapshot { transforms: SumTree, folds: SumTree, - buffer_snapshot: language::Snapshot, + buffer_snapshot: language::BufferSnapshot, pub version: usize, } -impl Snapshot { +impl FoldSnapshot { #[cfg(test)] pub fn text(&self) -> String { self.chunks(FoldOffset(0)..self.len(), None) @@ -553,7 +552,7 @@ impl Snapshot { (line_end - line_start) as u32 } - pub fn buffer_rows(&self, start_row: u32) -> BufferRows { + pub fn buffer_rows(&self, start_row: u32) -> FoldBufferRows { if start_row > self.transforms.summary().output.lines.row { panic!("invalid display row {}", start_row); } @@ -561,7 +560,7 @@ impl Snapshot { let fold_point = FoldPoint::new(start_row, 0); let mut cursor = self.transforms.cursor(); cursor.seek(&fold_point, Bias::Left, &()); - BufferRows { fold_point, cursor } + FoldBufferRows { fold_point, cursor } } pub fn max_point(&self) -> FoldPoint { @@ -624,7 +623,7 @@ impl Snapshot { &'a self, range: Range, theme: Option<&'a SyntaxTheme>, - ) -> Chunks<'a> { + ) -> FoldChunks<'a> { let mut transform_cursor = self.transforms.cursor::<(FoldOffset, usize)>(); transform_cursor.seek(&range.end, Bias::Right, &()); @@ -635,7 +634,7 @@ impl Snapshot { let overshoot = range.start.0 - transform_cursor.start().0 .0; let buffer_start = transform_cursor.start().1 + overshoot; - Chunks { + FoldChunks { transform_cursor, buffer_chunks: self.buffer_snapshot.chunks(buffer_start..buffer_end, theme), buffer_chunk: None, @@ -700,7 +699,7 @@ impl Snapshot { } fn intersecting_folds<'a, T>( - buffer: &'a text::Snapshot, + buffer: &'a text::BufferSnapshot, folds: &'a SumTree, range: Range, inclusive: bool, @@ -851,9 +850,9 @@ impl Default for FoldSummary { } impl sum_tree::Summary for FoldSummary { - type Context = text::Snapshot; + type Context = text::BufferSnapshot; - fn add_summary(&mut self, other: &Self, buffer: &text::Snapshot) { + fn add_summary(&mut self, other: &Self, buffer: &text::BufferSnapshot) { if other.min_start.cmp(&self.min_start, buffer).unwrap() == Ordering::Less { self.min_start = other.min_start.clone(); } @@ -877,30 +876,30 @@ impl sum_tree::Summary for FoldSummary { } impl<'a> sum_tree::Dimension<'a, FoldSummary> for Fold { - fn add_summary(&mut self, summary: &'a FoldSummary, _: &text::Snapshot) { + fn add_summary(&mut self, summary: &'a FoldSummary, _: &text::BufferSnapshot) { self.0.start = summary.start.clone(); self.0.end = summary.end.clone(); } } impl<'a> sum_tree::SeekTarget<'a, FoldSummary, Fold> for Fold { - fn cmp(&self, other: &Self, buffer: &text::Snapshot) -> Ordering { + fn cmp(&self, other: &Self, buffer: &text::BufferSnapshot) -> Ordering { self.0.cmp(&other.0, buffer).unwrap() } } impl<'a> sum_tree::Dimension<'a, FoldSummary> for usize { - fn add_summary(&mut self, summary: &'a FoldSummary, _: &text::Snapshot) { + fn add_summary(&mut self, summary: &'a FoldSummary, _: &text::BufferSnapshot) { *self += summary.count; } } -pub struct BufferRows<'a> { +pub struct FoldBufferRows<'a> { cursor: Cursor<'a, Transform, (FoldPoint, Point)>, fold_point: FoldPoint, } -impl<'a> Iterator for BufferRows<'a> { +impl<'a> Iterator for FoldBufferRows<'a> { type Item = u32; fn next(&mut self) -> Option { @@ -923,16 +922,16 @@ impl<'a> Iterator for BufferRows<'a> { } } -pub struct Chunks<'a> { +pub struct FoldChunks<'a> { transform_cursor: Cursor<'a, Transform, (FoldOffset, usize)>, - buffer_chunks: language::Chunks<'a>, + buffer_chunks: language::BufferChunks<'a>, buffer_chunk: Option<(usize, Chunk<'a>)>, buffer_offset: usize, output_offset: usize, max_output_offset: usize, } -impl<'a> Iterator for Chunks<'a> { +impl<'a> Iterator for FoldChunks<'a> { type Item = Chunk<'a>; fn next(&mut self) -> Option { @@ -1006,7 +1005,7 @@ impl<'a> sum_tree::Dimension<'a, TransformSummary> for FoldPoint { pub struct FoldOffset(pub usize); impl FoldOffset { - pub fn to_point(&self, snapshot: &Snapshot) -> FoldPoint { + pub fn to_point(&self, snapshot: &FoldSnapshot) -> FoldPoint { let mut cursor = snapshot .transforms .cursor::<(FoldOffset, TransformSummary)>(); @@ -1520,7 +1519,10 @@ mod tests { merged_ranges } - pub fn randomly_mutate(&mut self, rng: &mut impl Rng) -> Vec<(Snapshot, Vec)> { + pub fn randomly_mutate( + &mut self, + rng: &mut impl Rng, + ) -> Vec<(FoldSnapshot, Vec)> { let mut snapshot_edits = Vec::new(); match rng.gen_range(0..=100) { 0..=39 if !self.folds.is_empty() => { diff --git a/crates/editor/src/display_map/tab_map.rs b/crates/editor/src/display_map/tab_map.rs index 1a9163ba2b..69a70ecc12 100644 --- a/crates/editor/src/display_map/tab_map.rs +++ b/crates/editor/src/display_map/tab_map.rs @@ -1,4 +1,4 @@ -use super::fold_map::{self, FoldEdit, FoldPoint, Snapshot as FoldSnapshot, ToFoldPoint}; +use super::fold_map::{self, FoldEdit, FoldPoint, FoldSnapshot, ToFoldPoint}; use language::{rope, Chunk}; use parking_lot::Mutex; use std::{cmp, mem, ops::Range}; @@ -6,11 +6,11 @@ use sum_tree::Bias; use text::Point; use theme::SyntaxTheme; -pub struct TabMap(Mutex); +pub struct TabMap(Mutex); impl TabMap { - pub fn new(input: FoldSnapshot, tab_size: usize) -> (Self, Snapshot) { - let snapshot = Snapshot { + pub fn new(input: FoldSnapshot, tab_size: usize) -> (Self, TabSnapshot) { + let snapshot = TabSnapshot { fold_snapshot: input, tab_size, }; @@ -21,10 +21,10 @@ impl TabMap { &self, fold_snapshot: FoldSnapshot, mut fold_edits: Vec, - ) -> (Snapshot, Vec) { + ) -> (TabSnapshot, Vec) { let mut old_snapshot = self.0.lock(); let max_offset = old_snapshot.fold_snapshot.len(); - let new_snapshot = Snapshot { + let new_snapshot = TabSnapshot { fold_snapshot, tab_size: old_snapshot.tab_size, }; @@ -93,12 +93,12 @@ impl TabMap { } #[derive(Clone)] -pub struct Snapshot { +pub struct TabSnapshot { pub fold_snapshot: FoldSnapshot, pub tab_size: usize, } -impl Snapshot { +impl TabSnapshot { pub fn text_summary(&self) -> TextSummary { self.text_summary_for_range(TabPoint::zero()..self.max_point()) } @@ -155,7 +155,7 @@ impl Snapshot { &'a self, range: Range, theme: Option<&'a SyntaxTheme>, - ) -> Chunks<'a> { + ) -> TabChunks<'a> { let (input_start, expanded_char_column, to_next_stop) = self.to_fold_point(range.start, Bias::Left); let input_start = input_start.to_offset(&self.fold_snapshot); @@ -169,7 +169,7 @@ impl Snapshot { to_next_stop }; - Chunks { + TabChunks { fold_chunks: self.fold_snapshot.chunks(input_start..input_end, theme), column: expanded_char_column, output_position: range.start.0, @@ -183,7 +183,7 @@ impl Snapshot { } } - pub fn buffer_rows(&self, row: u32) -> fold_map::BufferRows { + pub fn buffer_rows(&self, row: u32) -> fold_map::FoldBufferRows { self.fold_snapshot.buffer_rows(row) } @@ -380,8 +380,8 @@ impl<'a> std::ops::AddAssign<&'a Self> for TextSummary { // Handles a tab width <= 16 const SPACES: &'static str = " "; -pub struct Chunks<'a> { - fold_chunks: fold_map::Chunks<'a>, +pub struct TabChunks<'a> { + fold_chunks: fold_map::FoldChunks<'a>, chunk: Chunk<'a>, column: usize, output_position: Point, @@ -390,7 +390,7 @@ pub struct Chunks<'a> { skip_leading_tab: bool, } -impl<'a> Iterator for Chunks<'a> { +impl<'a> Iterator for TabChunks<'a> { type Item = Chunk<'a>; fn next(&mut self) -> Option { @@ -457,9 +457,9 @@ mod tests { #[test] fn test_expand_tabs() { - assert_eq!(Snapshot::expand_tabs("\t".chars(), 0, 4), 0); - assert_eq!(Snapshot::expand_tabs("\t".chars(), 1, 4), 4); - assert_eq!(Snapshot::expand_tabs("\ta".chars(), 2, 4), 5); + assert_eq!(TabSnapshot::expand_tabs("\t".chars(), 0, 4), 0); + assert_eq!(TabSnapshot::expand_tabs("\t".chars(), 1, 4), 4); + assert_eq!(TabSnapshot::expand_tabs("\ta".chars(), 2, 4), 5); } #[gpui::test(iterations = 100)] diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index 04b6c00d6b..5eaea6d402 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -1,6 +1,6 @@ use super::{ fold_map, - tab_map::{self, Edit as TabEdit, Snapshot as TabSnapshot, TabPoint}, + tab_map::{self, Edit as TabEdit, TabPoint, TabSnapshot}, }; use gpui::{ fonts::FontId, text_layout::LineWrapper, Entity, ModelContext, ModelHandle, MutableAppContext, @@ -18,7 +18,7 @@ pub use super::tab_map::TextSummary; pub type Edit = text::Edit; pub struct WrapMap { - snapshot: Snapshot, + snapshot: WrapSnapshot, pending_edits: VecDeque<(TabSnapshot, Vec)>, interpolated_edits: Patch, edits_since_sync: Patch, @@ -32,7 +32,7 @@ impl Entity for WrapMap { } #[derive(Clone)] -pub struct Snapshot { +pub struct WrapSnapshot { tab_snapshot: TabSnapshot, transforms: SumTree, interpolated: bool, @@ -53,16 +53,16 @@ struct TransformSummary { #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] pub struct WrapPoint(pub super::Point); -pub struct Chunks<'a> { - input_chunks: tab_map::Chunks<'a>, +pub struct WrapChunks<'a> { + input_chunks: tab_map::TabChunks<'a>, input_chunk: Chunk<'a>, output_position: WrapPoint, max_output_row: u32, transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>, } -pub struct BufferRows<'a> { - input_buffer_rows: fold_map::BufferRows<'a>, +pub struct WrapBufferRows<'a> { + input_buffer_rows: fold_map::FoldBufferRows<'a>, input_buffer_row: u32, output_row: u32, soft_wrapped: bool, @@ -77,7 +77,7 @@ impl WrapMap { font_size: f32, wrap_width: Option, cx: &mut MutableAppContext, - ) -> (ModelHandle, Snapshot) { + ) -> (ModelHandle, WrapSnapshot) { let handle = cx.add_model(|cx| { let mut this = Self { font: (font_id, font_size), @@ -85,7 +85,7 @@ impl WrapMap { pending_edits: Default::default(), interpolated_edits: Default::default(), edits_since_sync: Default::default(), - snapshot: Snapshot::new(tab_snapshot), + snapshot: WrapSnapshot::new(tab_snapshot), background_task: None, }; this.set_wrap_width(wrap_width, cx); @@ -106,7 +106,7 @@ impl WrapMap { tab_snapshot: TabSnapshot, edits: Vec, cx: &mut ModelContext, - ) -> (Snapshot, Vec) { + ) -> (WrapSnapshot, Vec) { if self.wrap_width.is_some() { self.pending_edits.push_back((tab_snapshot, edits)); self.flush_edits(cx); @@ -291,7 +291,7 @@ impl WrapMap { } } -impl Snapshot { +impl WrapSnapshot { fn new(tab_snapshot: TabSnapshot) -> Self { let mut transforms = SumTree::new(); let extent = tab_snapshot.text_summary(); @@ -364,7 +364,7 @@ impl Snapshot { let old_snapshot = mem::replace( self, - Snapshot { + WrapSnapshot { tab_snapshot: new_tab_snapshot, transforms: new_transforms, interpolated: true, @@ -513,7 +513,7 @@ impl Snapshot { let old_snapshot = mem::replace( self, - Snapshot { + WrapSnapshot { tab_snapshot: new_tab_snapshot, transforms: new_transforms, interpolated: false, @@ -523,7 +523,7 @@ impl Snapshot { old_snapshot.compute_edits(tab_edits, self) } - fn compute_edits(&self, tab_edits: &[TabEdit], new_snapshot: &Snapshot) -> Patch { + fn compute_edits(&self, tab_edits: &[TabEdit], new_snapshot: &WrapSnapshot) -> Patch { let mut wrap_edits = Vec::new(); let mut old_cursor = self.transforms.cursor::(); let mut new_cursor = new_snapshot.transforms.cursor::(); @@ -564,7 +564,11 @@ impl Snapshot { .map(|h| h.text) } - pub fn chunks<'a>(&'a self, rows: Range, theme: Option<&'a SyntaxTheme>) -> Chunks<'a> { + pub fn chunks<'a>( + &'a self, + rows: Range, + theme: Option<&'a SyntaxTheme>, + ) -> WrapChunks<'a> { let output_start = WrapPoint::new(rows.start, 0); let output_end = WrapPoint::new(rows.end, 0); let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>(); @@ -576,7 +580,7 @@ impl Snapshot { let input_end = self .to_tab_point(output_end) .min(self.tab_snapshot.max_point()); - Chunks { + WrapChunks { input_chunks: self.tab_snapshot.chunks(input_start..input_end, theme), input_chunk: Default::default(), output_position: output_start, @@ -622,7 +626,7 @@ impl Snapshot { self.transforms.summary().output.longest_row } - pub fn buffer_rows(&self, start_row: u32) -> BufferRows { + pub fn buffer_rows(&self, start_row: u32) -> WrapBufferRows { let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>(); transforms.seek(&WrapPoint::new(start_row, 0), Bias::Left, &()); let mut input_row = transforms.start().1.row(); @@ -632,7 +636,7 @@ impl Snapshot { let soft_wrapped = transforms.item().map_or(false, |t| !t.is_isomorphic()); let mut input_buffer_rows = self.tab_snapshot.buffer_rows(input_row); let input_buffer_row = input_buffer_rows.next().unwrap(); - BufferRows { + WrapBufferRows { transforms, input_buffer_row, input_buffer_rows, @@ -727,7 +731,7 @@ impl Snapshot { } } -impl<'a> Iterator for Chunks<'a> { +impl<'a> Iterator for WrapChunks<'a> { type Item = Chunk<'a>; fn next(&mut self) -> Option { @@ -790,7 +794,7 @@ impl<'a> Iterator for Chunks<'a> { } } -impl<'a> Iterator for BufferRows<'a> { +impl<'a> Iterator for WrapBufferRows<'a> { type Item = Option; fn next(&mut self) -> Option { @@ -1224,7 +1228,7 @@ mod tests { } } - impl Snapshot { + impl WrapSnapshot { pub fn text(&self) -> String { self.text_chunks(0).collect() } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 4299807f97..294e9f229e 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -273,11 +273,11 @@ pub fn init(cx: &mut MutableAppContext, entry_openers: &mut Vec Range; + fn display_range(&self, map: &DisplaySnapshot) -> Range; fn spanned_rows( &self, include_end_if_at_line_start: bool, - map: &DisplayMapSnapshot, + map: &DisplaySnapshot, ) -> SpannedRows; } @@ -371,9 +371,9 @@ pub struct Editor { highlighted_row: Option, } -pub struct Snapshot { +pub struct EditorSnapshot { pub mode: EditorMode, - pub display_snapshot: DisplayMapSnapshot, + pub display_snapshot: DisplaySnapshot, pub placeholder_text: Option>, is_focused: bool, scroll_position: Vector2F, @@ -533,8 +533,8 @@ impl Editor { &self.buffer } - pub fn snapshot(&mut self, cx: &mut MutableAppContext) -> Snapshot { - Snapshot { + pub fn snapshot(&mut self, cx: &mut MutableAppContext) -> EditorSnapshot { + EditorSnapshot { mode: self.mode, display_snapshot: self.display_map.update(cx, |map, cx| map.snapshot(cx)), scroll_position: self.scroll_position, @@ -986,7 +986,7 @@ impl Editor { tail: DisplayPoint, head: DisplayPoint, overshoot: u32, - display_map: &DisplayMapSnapshot, + display_map: &DisplaySnapshot, cx: &mut ViewContext, ) { let start_row = cmp::min(tail.row(), head.row()); @@ -2966,7 +2966,7 @@ impl Editor { fn build_columnar_selection( &mut self, - display_map: &DisplayMapSnapshot, + display_map: &DisplaySnapshot, row: u32, columns: &Range, reversed: bool, @@ -3271,7 +3271,7 @@ impl Editor { self.unfold_ranges(ranges, cx); } - fn is_line_foldable(&self, display_map: &DisplayMapSnapshot, display_row: u32) -> bool { + fn is_line_foldable(&self, display_map: &DisplaySnapshot, display_row: u32) -> bool { let max_point = display_map.max_point(); if display_row >= max_point.row() { false @@ -3293,7 +3293,7 @@ impl Editor { fn foldable_range_for_line( &self, - display_map: &DisplayMapSnapshot, + display_map: &DisplaySnapshot, start_row: u32, ) -> Range { let max_point = display_map.max_point(); @@ -3450,7 +3450,7 @@ impl Editor { } } -impl Snapshot { +impl EditorSnapshot { pub fn is_focused(&self) -> bool { self.is_focused } @@ -3468,8 +3468,8 @@ impl Snapshot { } } -impl Deref for Snapshot { - type Target = DisplayMapSnapshot; +impl Deref for EditorSnapshot { + type Target = DisplaySnapshot; fn deref(&self) -> &Self::Target { &self.display_snapshot @@ -3525,7 +3525,7 @@ impl EditorSettings { } fn compute_scroll_position( - snapshot: &DisplayMapSnapshot, + snapshot: &DisplaySnapshot, mut scroll_position: Vector2F, scroll_top_anchor: &Anchor, ) -> Vector2F { @@ -3606,7 +3606,7 @@ impl View for Editor { } impl SelectionExt for Selection { - fn display_range(&self, map: &DisplayMapSnapshot) -> Range { + fn display_range(&self, map: &DisplaySnapshot) -> Range { let start = self.start.to_display_point(map); let end = self.end.to_display_point(map); if self.reversed { @@ -3619,7 +3619,7 @@ impl SelectionExt for Selection { fn spanned_rows( &self, include_end_if_at_line_start: bool, - map: &DisplayMapSnapshot, + map: &DisplaySnapshot, ) -> SpannedRows { let display_start = self.start.to_display_point(map); let mut display_end = self.end.to_display_point(map); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 45764e65fb..a53fdd3a8b 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1,8 +1,8 @@ use crate::display_map::{BlockContext, ToDisplayPoint}; use super::{ - DisplayPoint, Editor, EditorMode, EditorSettings, EditorStyle, Input, Scroll, Select, - SelectPhase, Snapshot, SoftWrap, MAX_LINE_LEN, + DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, Input, Scroll, + Select, SelectPhase, SoftWrap, MAX_LINE_LEN, }; use clock::ReplicaId; use gpui::{ @@ -49,7 +49,7 @@ impl EditorElement { self.view.upgrade(cx).unwrap().update(cx, f) } - fn snapshot(&self, cx: &mut MutableAppContext) -> Snapshot { + fn snapshot(&self, cx: &mut MutableAppContext) -> EditorSnapshot { self.update_view(cx, |view, cx| view.snapshot(cx)) } @@ -434,7 +434,7 @@ impl EditorElement { } } - fn max_line_number_width(&self, snapshot: &Snapshot, cx: &LayoutContext) -> f32 { + fn max_line_number_width(&self, snapshot: &EditorSnapshot, cx: &LayoutContext) -> f32 { let digit_count = (snapshot.buffer_row_count() as f32).log10().floor() as usize + 1; let style = &self.settings.style; @@ -458,7 +458,7 @@ impl EditorElement { &self, rows: Range, active_rows: &BTreeMap, - snapshot: &Snapshot, + snapshot: &EditorSnapshot, cx: &LayoutContext, ) -> Vec> { let style = &self.settings.style; @@ -504,7 +504,7 @@ impl EditorElement { fn layout_lines( &mut self, mut rows: Range, - snapshot: &mut Snapshot, + snapshot: &mut EditorSnapshot, cx: &LayoutContext, ) -> Vec { rows.end = cmp::min(rows.end, snapshot.max_point().row() + 1); @@ -623,7 +623,7 @@ impl EditorElement { fn layout_blocks( &mut self, rows: Range, - snapshot: &Snapshot, + snapshot: &EditorSnapshot, text_width: f32, line_height: f32, style: &EditorStyle, @@ -923,7 +923,7 @@ pub struct LayoutState { gutter_padding: f32, text_size: Vector2F, style: EditorStyle, - snapshot: Snapshot, + snapshot: EditorSnapshot, active_rows: BTreeMap, highlighted_row: Option, line_layouts: Vec, @@ -961,7 +961,7 @@ impl LayoutState { fn layout_line( row: u32, - snapshot: &Snapshot, + snapshot: &EditorSnapshot, style: &EditorStyle, layout_cache: &TextLayoutCache, ) -> text_layout::Line { @@ -998,7 +998,7 @@ pub struct PaintState { impl PaintState { fn point_for_position( &self, - snapshot: &Snapshot, + snapshot: &EditorSnapshot, layout: &LayoutState, position: Vector2F, ) -> (DisplayPoint, u32) { diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rs index bffd21be2a..9ba6cbc08d 100644 --- a/crates/editor/src/movement.rs +++ b/crates/editor/src/movement.rs @@ -1,9 +1,9 @@ -use super::{Bias, DisplayMapSnapshot, DisplayPoint, SelectionGoal, ToDisplayPoint}; +use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint}; use anyhow::Result; use std::{cmp, ops::Range}; use text::ToPoint; -pub fn left(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> Result { +pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> Result { if point.column() > 0 { *point.column_mut() -= 1; } else if point.row() > 0 { @@ -13,7 +13,7 @@ pub fn left(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> Result Result { +pub fn right(map: &DisplaySnapshot, mut point: DisplayPoint) -> Result { let max_column = map.line_len(point.row()); if point.column() < max_column { *point.column_mut() += 1; @@ -25,7 +25,7 @@ pub fn right(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> Result Result<(DisplayPoint, SelectionGoal)> { @@ -61,7 +61,7 @@ pub fn up( } pub fn down( - map: &DisplayMapSnapshot, + map: &DisplaySnapshot, mut point: DisplayPoint, goal: SelectionGoal, ) -> Result<(DisplayPoint, SelectionGoal)> { @@ -98,7 +98,7 @@ pub fn down( } pub fn line_beginning( - map: &DisplayMapSnapshot, + map: &DisplaySnapshot, point: DisplayPoint, toggle_indent: bool, ) -> DisplayPoint { @@ -110,12 +110,12 @@ pub fn line_beginning( } } -pub fn line_end(map: &DisplayMapSnapshot, point: DisplayPoint) -> DisplayPoint { +pub fn line_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint { let line_end = DisplayPoint::new(point.row(), map.line_len(point.row())); map.clip_point(line_end, Bias::Left) } -pub fn prev_word_boundary(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> DisplayPoint { +pub fn prev_word_boundary(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint { let mut line_start = 0; if point.row() > 0 { if let Some(indent) = map.soft_wrap_indent(point.row() - 1) { @@ -154,7 +154,7 @@ pub fn prev_word_boundary(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> boundary } -pub fn next_word_boundary(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> DisplayPoint { +pub fn next_word_boundary(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint { let mut prev_char_kind = None; for c in map.chars_at(point) { let char_kind = char_kind(c); @@ -181,7 +181,7 @@ pub fn next_word_boundary(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> point } -pub fn is_inside_word(map: &DisplayMapSnapshot, point: DisplayPoint) -> bool { +pub fn is_inside_word(map: &DisplaySnapshot, point: DisplayPoint) -> bool { let ix = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left); let text = &map.buffer_snapshot; let next_char_kind = text.chars_at(ix).next().map(char_kind); @@ -189,7 +189,7 @@ pub fn is_inside_word(map: &DisplayMapSnapshot, point: DisplayPoint) -> bool { prev_char_kind.zip(next_char_kind) == Some((CharKind::Word, CharKind::Word)) } -pub fn surrounding_word(map: &DisplayMapSnapshot, point: DisplayPoint) -> Range { +pub fn surrounding_word(map: &DisplaySnapshot, point: DisplayPoint) -> Range { let mut start = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left); let mut end = start; diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 55346fc9dd..aadf5c5d59 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -68,8 +68,8 @@ pub struct Buffer { pub(crate) operations: Vec, } -pub struct Snapshot { - text: text::Snapshot, +pub struct BufferSnapshot { + text: text::BufferSnapshot, tree: Option, diagnostics: AnchorRangeMultimap, diagnostics_update_count: usize, @@ -96,7 +96,7 @@ struct LanguageServerState { #[derive(Clone)] struct LanguageServerSnapshot { - buffer_snapshot: text::Snapshot, + buffer_snapshot: text::BufferSnapshot, version: usize, path: Arc, } @@ -172,7 +172,7 @@ struct SyntaxTree { #[derive(Clone)] struct AutoindentRequest { selection_set_ids: HashSet, - before_edit: Snapshot, + before_edit: BufferSnapshot, edited: AnchorSet, inserted: Option, } @@ -185,7 +185,7 @@ struct IndentSuggestion { struct TextProvider<'a>(&'a Rope); -struct Highlights<'a> { +struct BufferChunkHighlights<'a> { captures: tree_sitter::QueryCaptures<'a, 'a, TextProvider<'a>>, next_capture: Option<(tree_sitter::QueryMatch<'a, 'a>, usize)>, stack: Vec<(usize, HighlightId)>, @@ -194,7 +194,7 @@ struct Highlights<'a> { _query_cursor: QueryCursorHandle, } -pub struct Chunks<'a> { +pub struct BufferChunks<'a> { range: Range, chunks: rope::Chunks<'a>, diagnostic_endpoints: Peekable>, @@ -202,7 +202,7 @@ pub struct Chunks<'a> { warning_depth: usize, information_depth: usize, hint_depth: usize, - highlights: Option>, + highlights: Option>, } #[derive(Clone, Copy, Debug, Default)] @@ -336,8 +336,8 @@ impl Buffer { } } - pub fn snapshot(&self) -> Snapshot { - Snapshot { + pub fn snapshot(&self) -> BufferSnapshot { + BufferSnapshot { text: self.text.snapshot(), tree: self.syntax_tree(), diagnostics: self.diagnostics.clone(), @@ -1512,7 +1512,7 @@ impl Deref for Buffer { } } -impl Snapshot { +impl BufferSnapshot { fn suggest_autoindents<'a>( &'a self, row_range: Range, @@ -1626,7 +1626,7 @@ impl Snapshot { &'a self, range: Range, theme: Option<&'a SyntaxTheme>, - ) -> Chunks<'a> { + ) -> BufferChunks<'a> { let range = range.start.to_offset(self)..range.end.to_offset(self); let mut highlights = None; @@ -1662,7 +1662,7 @@ impl Snapshot { tree.root_node(), TextProvider(self.text.as_rope()), ); - highlights = Some(Highlights { + highlights = Some(BufferChunkHighlights { captures, next_capture: None, stack: Default::default(), @@ -1676,7 +1676,7 @@ impl Snapshot { let diagnostic_endpoints = diagnostic_endpoints.into_iter().peekable(); let chunks = self.text.as_rope().chunks_in_range(range.clone()); - Chunks { + BufferChunks { range, chunks, diagnostic_endpoints, @@ -1703,7 +1703,7 @@ impl Snapshot { } } -impl Clone for Snapshot { +impl Clone for BufferSnapshot { fn clone(&self) -> Self { Self { text: self.text.clone(), @@ -1717,8 +1717,8 @@ impl Clone for Snapshot { } } -impl Deref for Snapshot { - type Target = text::Snapshot; +impl Deref for BufferSnapshot { + type Target = text::BufferSnapshot; fn deref(&self) -> &Self::Target { &self.text @@ -1743,9 +1743,9 @@ impl<'a> Iterator for ByteChunks<'a> { } } -unsafe impl<'a> Send for Chunks<'a> {} +unsafe impl<'a> Send for BufferChunks<'a> {} -impl<'a> Chunks<'a> { +impl<'a> BufferChunks<'a> { pub fn seek(&mut self, offset: usize) { self.range.start = offset; self.chunks.seek(self.range.start); @@ -1804,7 +1804,7 @@ impl<'a> Chunks<'a> { } } -impl<'a> Iterator for Chunks<'a> { +impl<'a> Iterator for BufferChunks<'a> { type Item = Chunk<'a>; fn next(&mut self) -> Option { diff --git a/crates/language/src/excerpt_list.rs b/crates/language/src/excerpt_list.rs index bd2fa558a6..1791031de9 100644 --- a/crates/language/src/excerpt_list.rs +++ b/crates/language/src/excerpt_list.rs @@ -47,7 +47,7 @@ pub struct ExcerptProperties<'a, T> { #[derive(Clone)] struct Excerpt { id: ExcerptId, - buffer: buffer::Snapshot, + buffer: buffer::BufferSnapshot, range: Range, text_summary: TextSummary, header_height: u8, @@ -66,7 +66,7 @@ pub struct Chunks<'a> { range: Range, cursor: Cursor<'a, Excerpt, usize>, header_height: u8, - entry_chunks: Option>, + entry_chunks: Option>, theme: Option<&'a SyntaxTheme>, } @@ -339,7 +339,7 @@ impl Snapshot { impl Excerpt { fn new( id: ExcerptId, - buffer: buffer::Snapshot, + buffer: buffer::BufferSnapshot, range: Range, header_height: u8, ) -> Self { diff --git a/crates/text/src/anchor.rs b/crates/text/src/anchor.rs index 846c57274b..5f02a0e03b 100644 --- a/crates/text/src/anchor.rs +++ b/crates/text/src/anchor.rs @@ -1,4 +1,4 @@ -use crate::{rope::TextDimension, Snapshot}; +use crate::{rope::TextDimension, BufferSnapshot}; use super::{Buffer, FromAnchor, FullOffset, Point, ToOffset}; use anyhow::Result; @@ -83,7 +83,7 @@ impl Anchor { } } - pub fn cmp<'a>(&self, other: &Anchor, buffer: &Snapshot) -> Result { + pub fn cmp<'a>(&self, other: &Anchor, buffer: &BufferSnapshot) -> Result { if self == other { return Ok(Ordering::Equal); } @@ -115,7 +115,7 @@ impl Anchor { } } - pub fn summary<'a, D>(&self, content: &'a Snapshot) -> D + pub fn summary<'a, D>(&self, content: &'a BufferSnapshot) -> D where D: TextDimension<'a>, { @@ -132,7 +132,10 @@ impl AnchorMap { self.entries.len() } - pub fn iter<'a, D>(&'a self, snapshot: &'a Snapshot) -> impl Iterator + 'a + pub fn iter<'a, D>( + &'a self, + snapshot: &'a BufferSnapshot, + ) -> impl Iterator + 'a where D: 'a + TextDimension<'a>, { @@ -155,7 +158,7 @@ impl AnchorSet { self.0.len() } - pub fn iter<'a, D>(&'a self, content: &'a Snapshot) -> impl Iterator + 'a + pub fn iter<'a, D>(&'a self, content: &'a BufferSnapshot) -> impl Iterator + 'a where D: 'a + TextDimension<'a>, { @@ -188,7 +191,7 @@ impl AnchorRangeMap { pub fn ranges<'a, D>( &'a self, - content: &'a Snapshot, + content: &'a BufferSnapshot, ) -> impl Iterator, &'a T)> + 'a where D: 'a + TextDimension<'a>, @@ -206,7 +209,7 @@ impl AnchorRangeMap { pub fn intersecting_ranges<'a, D, I>( &'a self, range: Range<(I, Bias)>, - content: &'a Snapshot, + content: &'a BufferSnapshot, ) -> impl Iterator, &'a T)> + 'a where D: 'a + TextDimension<'a>, @@ -243,7 +246,7 @@ impl AnchorRangeMap { pub fn min_by_key<'a, D, F, K>( &self, - content: &'a Snapshot, + content: &'a BufferSnapshot, mut extract_key: F, ) -> Option<(Range, &T)> where @@ -259,7 +262,7 @@ impl AnchorRangeMap { pub fn max_by_key<'a, D, F, K>( &self, - content: &'a Snapshot, + content: &'a BufferSnapshot, mut extract_key: F, ) -> Option<(Range, &T)> where @@ -273,7 +276,11 @@ impl AnchorRangeMap { .map(|(range, value)| (self.resolve_range(range, &content), value)) } - fn resolve_range<'a, D>(&self, range: &Range, content: &'a Snapshot) -> Range + fn resolve_range<'a, D>( + &self, + range: &Range, + content: &'a BufferSnapshot, + ) -> Range where D: 'a + TextDimension<'a>, { @@ -330,7 +337,10 @@ impl AnchorRangeSet { self.0.version() } - pub fn ranges<'a, D>(&'a self, content: &'a Snapshot) -> impl 'a + Iterator> + pub fn ranges<'a, D>( + &'a self, + content: &'a BufferSnapshot, + ) -> impl 'a + Iterator> where D: 'a + TextDimension<'a>, { @@ -357,7 +367,7 @@ impl AnchorRangeMultimap { pub fn intersecting_ranges<'a, I, O>( &'a self, range: Range, - content: &'a Snapshot, + content: &'a BufferSnapshot, inclusive: bool, ) -> impl Iterator, &T)> + 'a where @@ -451,7 +461,7 @@ impl AnchorRangeMultimap { pub fn filter<'a, O, F>( &'a self, - content: &'a Snapshot, + content: &'a BufferSnapshot, mut f: F, ) -> impl 'a + Iterator, &T)> where @@ -560,19 +570,19 @@ impl<'a> sum_tree::SeekTarget<'a, AnchorRangeMultimapSummary, FullOffsetRange> f } pub trait AnchorRangeExt { - fn cmp(&self, b: &Range, buffer: &Snapshot) -> Result; - fn to_offset(&self, content: &Snapshot) -> Range; + fn cmp(&self, b: &Range, buffer: &BufferSnapshot) -> Result; + fn to_offset(&self, content: &BufferSnapshot) -> Range; } impl AnchorRangeExt for Range { - fn cmp(&self, other: &Range, buffer: &Snapshot) -> Result { + fn cmp(&self, other: &Range, buffer: &BufferSnapshot) -> Result { Ok(match self.start.cmp(&other.start, buffer)? { Ordering::Equal => other.end.cmp(&self.end, buffer)?, ord @ _ => ord, }) } - fn to_offset(&self, content: &Snapshot) -> Range { + fn to_offset(&self, content: &BufferSnapshot) -> Range { self.start.to_offset(&content)..self.end.to_offset(&content) } } diff --git a/crates/text/src/selection.rs b/crates/text/src/selection.rs index eaa2409772..6af1039527 100644 --- a/crates/text/src/selection.rs +++ b/crates/text/src/selection.rs @@ -1,6 +1,6 @@ use sum_tree::Bias; -use crate::{rope::TextDimension, Snapshot}; +use crate::{rope::TextDimension, BufferSnapshot}; use super::{AnchorRangeMap, Buffer, Point, ToOffset, ToPoint}; use std::{cmp::Ordering, ops::Range, sync::Arc}; @@ -105,7 +105,7 @@ impl SelectionSet { pub fn selections<'a, D>( &'a self, - content: &'a Snapshot, + content: &'a BufferSnapshot, ) -> impl 'a + Iterator> where D: 'a + TextDimension<'a>, @@ -124,7 +124,7 @@ impl SelectionSet { pub fn intersecting_selections<'a, D, I>( &'a self, range: Range<(I, Bias)>, - content: &'a Snapshot, + content: &'a BufferSnapshot, ) -> impl 'a + Iterator> where D: 'a + TextDimension<'a>, @@ -141,7 +141,7 @@ impl SelectionSet { }) } - pub fn oldest_selection<'a, D>(&'a self, content: &'a Snapshot) -> Option> + pub fn oldest_selection<'a, D>(&'a self, content: &'a BufferSnapshot) -> Option> where D: 'a + TextDimension<'a>, { @@ -156,7 +156,7 @@ impl SelectionSet { }) } - pub fn newest_selection<'a, D>(&'a self, content: &'a Snapshot) -> Option> + pub fn newest_selection<'a, D>(&'a self, content: &'a BufferSnapshot) -> Option> where D: 'a + TextDimension<'a>, { diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs index 3a19977fa5..f99de77ab6 100644 --- a/crates/text/src/text.rs +++ b/crates/text/src/text.rs @@ -37,7 +37,7 @@ pub use sum_tree::Bias; use sum_tree::{FilterCursor, SumTree}; pub struct Buffer { - snapshot: Snapshot, + snapshot: BufferSnapshot, last_edit: clock::Local, history: History, selections: HashMap, @@ -51,7 +51,7 @@ pub struct Buffer { } #[derive(Clone, Debug)] -pub struct Snapshot { +pub struct BufferSnapshot { visible_text: Rope, deleted_text: Rope, undo_map: UndoMap, @@ -473,7 +473,7 @@ impl Buffer { } Buffer { - snapshot: Snapshot { + snapshot: BufferSnapshot { visible_text, deleted_text: Rope::new(), fragments, @@ -497,8 +497,8 @@ impl Buffer { self.version.clone() } - pub fn snapshot(&self) -> Snapshot { - Snapshot { + pub fn snapshot(&self) -> BufferSnapshot { + BufferSnapshot { visible_text: self.visible_text.clone(), deleted_text: self.deleted_text.clone(), undo_map: self.undo_map.clone(), @@ -1476,14 +1476,14 @@ impl Buffer { } impl Deref for Buffer { - type Target = Snapshot; + type Target = BufferSnapshot; fn deref(&self) -> &Self::Target { &self.snapshot } } -impl Snapshot { +impl BufferSnapshot { pub fn as_rope(&self) -> &Rope { &self.visible_text } @@ -2254,9 +2254,9 @@ impl Operation { } pub trait ToOffset { - fn to_offset<'a>(&self, content: &Snapshot) -> usize; + fn to_offset<'a>(&self, content: &BufferSnapshot) -> usize; - fn to_full_offset<'a>(&self, content: &Snapshot, bias: Bias) -> FullOffset { + fn to_full_offset<'a>(&self, content: &BufferSnapshot, bias: Bias) -> FullOffset { let offset = self.to_offset(&content); let mut cursor = content.fragments.cursor::(); cursor.seek(&offset, bias, &None); @@ -2265,30 +2265,30 @@ pub trait ToOffset { } impl ToOffset for Point { - fn to_offset<'a>(&self, content: &Snapshot) -> usize { + fn to_offset<'a>(&self, content: &BufferSnapshot) -> usize { content.visible_text.point_to_offset(*self) } } impl ToOffset for PointUtf16 { - fn to_offset<'a>(&self, content: &Snapshot) -> usize { + fn to_offset<'a>(&self, content: &BufferSnapshot) -> usize { content.visible_text.point_utf16_to_offset(*self) } } impl ToOffset for usize { - fn to_offset<'a>(&self, content: &Snapshot) -> usize { + fn to_offset<'a>(&self, content: &BufferSnapshot) -> usize { assert!(*self <= content.len(), "offset is out of range"); *self } } impl ToOffset for Anchor { - fn to_offset<'a>(&self, content: &Snapshot) -> usize { + fn to_offset<'a>(&self, content: &BufferSnapshot) -> usize { content.summary_for_anchor(self) } - fn to_full_offset<'a>(&self, content: &Snapshot, bias: Bias) -> FullOffset { + fn to_full_offset<'a>(&self, content: &BufferSnapshot, bias: Bias) -> FullOffset { if content.version == self.version { self.full_offset } else { @@ -2312,45 +2312,45 @@ impl ToOffset for Anchor { } impl<'a> ToOffset for &'a Anchor { - fn to_offset(&self, content: &Snapshot) -> usize { + fn to_offset(&self, content: &BufferSnapshot) -> usize { content.summary_for_anchor(self) } } pub trait ToPoint { - fn to_point<'a>(&self, content: &Snapshot) -> Point; + fn to_point<'a>(&self, content: &BufferSnapshot) -> Point; } impl ToPoint for Anchor { - fn to_point<'a>(&self, content: &Snapshot) -> Point { + fn to_point<'a>(&self, content: &BufferSnapshot) -> Point { content.summary_for_anchor(self) } } impl ToPoint for usize { - fn to_point<'a>(&self, content: &Snapshot) -> Point { + fn to_point<'a>(&self, content: &BufferSnapshot) -> Point { content.visible_text.offset_to_point(*self) } } impl ToPoint for Point { - fn to_point<'a>(&self, _: &Snapshot) -> Point { + fn to_point<'a>(&self, _: &BufferSnapshot) -> Point { *self } } pub trait FromAnchor { - fn from_anchor(anchor: &Anchor, content: &Snapshot) -> Self; + fn from_anchor(anchor: &Anchor, content: &BufferSnapshot) -> Self; } impl FromAnchor for Point { - fn from_anchor(anchor: &Anchor, content: &Snapshot) -> Self { + fn from_anchor(anchor: &Anchor, content: &BufferSnapshot) -> Self { anchor.to_point(content) } } impl FromAnchor for usize { - fn from_anchor(anchor: &Anchor, content: &Snapshot) -> Self { + fn from_anchor(anchor: &Anchor, content: &BufferSnapshot) -> Self { anchor.to_offset(content) } }