Give more specific names to all snapshot and text iterator types

This commit is contained in:
Max Brunsfeld 2021-12-08 09:24:00 -08:00
parent ad33111a22
commit fa379885f1
13 changed files with 229 additions and 207 deletions

View file

@ -3,9 +3,6 @@ mod fold_map;
mod tab_map; mod tab_map;
mod wrap_map; mod wrap_map;
pub use block_map::{
AlignedBlock, BlockContext, BlockDisposition, BlockId, BlockProperties, BufferRows, Chunks,
};
use block_map::{BlockMap, BlockPoint}; use block_map::{BlockMap, BlockPoint};
use fold_map::{FoldMap, ToFoldPoint as _}; use fold_map::{FoldMap, ToFoldPoint as _};
use gpui::{fonts::FontId, ElementBox, Entity, ModelContext, ModelHandle}; use gpui::{fonts::FontId, ElementBox, Entity, ModelContext, ModelHandle};
@ -19,8 +16,13 @@ use tab_map::TabMap;
use theme::SyntaxTheme; use theme::SyntaxTheme;
use wrap_map::WrapMap; use wrap_map::WrapMap;
pub use block_map::{
AlignedBlock, BlockBufferRows as DisplayBufferRows, BlockChunks as DisplayChunks, BlockContext,
BlockDisposition, BlockId, BlockProperties,
};
pub trait ToDisplayPoint { pub trait ToDisplayPoint {
fn to_display_point(&self, map: &DisplayMapSnapshot) -> DisplayPoint; fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint;
} }
pub struct DisplayMap { pub struct DisplayMap {
@ -61,7 +63,7 @@ impl DisplayMap {
} }
} }
pub fn snapshot(&self, cx: &mut ModelContext<Self>) -> DisplayMapSnapshot { pub fn snapshot(&self, cx: &mut ModelContext<Self>) -> DisplaySnapshot {
let buffer_snapshot = self.buffer.read(cx).snapshot(); let buffer_snapshot = self.buffer.read(cx).snapshot();
let edits = self.buffer_subscription.consume().into_inner(); let edits = self.buffer_subscription.consume().into_inner();
let (folds_snapshot, edits) = self.fold_map.read(buffer_snapshot, edits); 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)); .update(cx, |map, cx| map.sync(tabs_snapshot.clone(), edits, cx));
let blocks_snapshot = self.block_map.read(wraps_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(), buffer_snapshot: self.buffer.read(cx).snapshot(),
folds_snapshot, folds_snapshot,
tabs_snapshot, tabs_snapshot,
@ -176,15 +178,15 @@ impl DisplayMap {
} }
} }
pub struct DisplayMapSnapshot { pub struct DisplaySnapshot {
pub buffer_snapshot: language::Snapshot, pub buffer_snapshot: language::BufferSnapshot,
folds_snapshot: fold_map::Snapshot, folds_snapshot: fold_map::FoldSnapshot,
tabs_snapshot: tab_map::Snapshot, tabs_snapshot: tab_map::TabSnapshot,
wraps_snapshot: wrap_map::Snapshot, wraps_snapshot: wrap_map::WrapSnapshot,
blocks_snapshot: block_map::BlockSnapshot, blocks_snapshot: block_map::BlockSnapshot,
} }
impl DisplayMapSnapshot { impl DisplaySnapshot {
#[cfg(test)] #[cfg(test)]
pub fn fold_count(&self) -> usize { pub fn fold_count(&self) -> usize {
self.folds_snapshot.fold_count() self.folds_snapshot.fold_count()
@ -194,7 +196,7 @@ impl DisplayMapSnapshot {
self.buffer_snapshot.len() == 0 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) self.blocks_snapshot.buffer_rows(start_row)
} }
@ -260,7 +262,7 @@ impl DisplayMapSnapshot {
&'a self, &'a self,
display_rows: Range<u32>, display_rows: Range<u32>,
theme: Option<&'a SyntaxTheme>, theme: Option<&'a SyntaxTheme>,
) -> block_map::Chunks<'a> { ) -> DisplayChunks<'a> {
self.blocks_snapshot.chunks(display_rows, theme) self.blocks_snapshot.chunks(display_rows, theme)
} }
@ -420,11 +422,11 @@ impl DisplayPoint {
&mut self.0.column &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) 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 unblocked_point = map.blocks_snapshot.to_wrap_point(self.0);
let unwrapped_point = map.wraps_snapshot.to_tab_point(unblocked_point); let unwrapped_point = map.wraps_snapshot.to_tab_point(unblocked_point);
let unexpanded_point = map.tabs_snapshot.to_fold_point(unwrapped_point, bias).0; let unexpanded_point = map.tabs_snapshot.to_fold_point(unwrapped_point, bias).0;
@ -433,19 +435,19 @@ impl DisplayPoint {
} }
impl ToDisplayPoint for usize { 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) map.point_to_display_point(self.to_point(&map.buffer_snapshot), Bias::Left)
} }
} }
impl ToDisplayPoint for Point { 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) map.point_to_display_point(*self, Bias::Left)
} }
} }
impl ToDisplayPoint for Anchor { 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) self.to_point(&map.buffer_snapshot).to_display_point(map)
} }
} }

View file

@ -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 gpui::{AppContext, ElementBox, ModelHandle};
use language::{Buffer, Chunk}; use language::{Buffer, Chunk};
use parking_lot::Mutex; use parking_lot::Mutex;
@ -93,17 +93,17 @@ struct TransformSummary {
output_rows: u32, output_rows: u32,
} }
pub struct Chunks<'a> { pub struct BlockChunks<'a> {
transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>, transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>,
input_chunks: wrap_map::Chunks<'a>, input_chunks: wrap_map::WrapChunks<'a>,
input_chunk: Chunk<'a>, input_chunk: Chunk<'a>,
output_row: u32, output_row: u32,
max_output_row: u32, max_output_row: u32,
} }
pub struct BufferRows<'a> { pub struct BlockBufferRows<'a> {
transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>, 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, output_row: u32,
started: bool, started: bool,
} }
@ -476,7 +476,11 @@ impl BlockSnapshot {
.collect() .collect()
} }
pub fn chunks<'a>(&'a self, rows: Range<u32>, theme: Option<&'a SyntaxTheme>) -> Chunks<'a> { pub fn chunks<'a>(
&'a self,
rows: Range<u32>,
theme: Option<&'a SyntaxTheme>,
) -> BlockChunks<'a> {
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows); let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(); let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
let input_end = { let input_end = {
@ -503,7 +507,7 @@ impl BlockSnapshot {
}; };
cursor.start().1 .0 + overshoot cursor.start().1 .0 + overshoot
}; };
Chunks { BlockChunks {
input_chunks: self.wrap_snapshot.chunks(input_start..input_end, theme), input_chunks: self.wrap_snapshot.chunks(input_start..input_end, theme),
input_chunk: Default::default(), input_chunk: Default::default(),
transforms: cursor, 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)>(); let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
cursor.seek(&BlockRow(start_row), Bias::Right, &()); cursor.seek(&BlockRow(start_row), Bias::Right, &());
let (output_start, input_start) = cursor.start(); let (output_start, input_start) = cursor.start();
@ -522,7 +526,7 @@ impl BlockSnapshot {
0 0
}; };
let input_start_row = input_start.0 + overshoot; let input_start_row = input_start.0 + overshoot;
BufferRows { BlockBufferRows {
transforms: cursor, transforms: cursor,
input_buffer_rows: self.wrap_snapshot.buffer_rows(input_start_row), input_buffer_rows: self.wrap_snapshot.buffer_rows(input_start_row),
output_row: 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>; type Item = Chunk<'a>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -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<u32>; type Item = Option<u32>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {

View file

@ -1,6 +1,5 @@
use language::{ use language::{
Anchor, AnchorRangeExt, Chunk, Edit, Point, PointUtf16, Snapshot as BufferSnapshot, Anchor, AnchorRangeExt, BufferSnapshot, Chunk, Edit, Point, PointUtf16, TextSummary, ToOffset,
TextSummary, ToOffset,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use std::{ use std::{
@ -13,7 +12,7 @@ use sum_tree::{Bias, Cursor, FilterCursor, SumTree};
use theme::SyntaxTheme; use theme::SyntaxTheme;
pub trait ToFoldPoint { 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)] #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
@ -41,14 +40,14 @@ impl FoldPoint {
&mut self.0.column &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)>(); let mut cursor = snapshot.transforms.cursor::<(FoldPoint, Point)>();
cursor.seek(self, Bias::Right, &()); cursor.seek(self, Bias::Right, &());
let overshoot = self.0 - cursor.start().0 .0; let overshoot = self.0 - cursor.start().0 .0;
cursor.start().1 + overshoot 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)>(); let mut cursor = snapshot.transforms.cursor::<(FoldPoint, Point)>();
cursor.seek(self, Bias::Right, &()); cursor.seek(self, Bias::Right, &());
let overshoot = self.0 - cursor.start().0 .0; let overshoot = self.0 - cursor.start().0 .0;
@ -57,7 +56,7 @@ impl FoldPoint {
.to_offset(cursor.start().1 + overshoot) .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 let mut cursor = snapshot
.transforms .transforms
.cursor::<(FoldPoint, TransformSummary)>(); .cursor::<(FoldPoint, TransformSummary)>();
@ -77,7 +76,7 @@ impl FoldPoint {
} }
impl ToFoldPoint for Point { 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)>(); let mut cursor = snapshot.transforms.cursor::<(Point, FoldPoint)>();
cursor.seek(self, Bias::Right, &()); cursor.seek(self, Bias::Right, &());
if cursor.item().map_or(false, |t| t.is_fold()) { if cursor.item().map_or(false, |t| t.is_fold()) {
@ -102,7 +101,7 @@ impl<'a> FoldMapWriter<'a> {
pub fn fold<T: ToOffset>( pub fn fold<T: ToOffset>(
&mut self, &mut self,
ranges: impl IntoIterator<Item = Range<T>>, ranges: impl IntoIterator<Item = Range<T>>,
) -> (Snapshot, Vec<FoldEdit>) { ) -> (FoldSnapshot, Vec<FoldEdit>) {
let mut edits = Vec::new(); let mut edits = Vec::new();
let mut folds = Vec::new(); let mut folds = Vec::new();
let buffer = self.0.buffer.lock().clone(); let buffer = self.0.buffer.lock().clone();
@ -133,7 +132,7 @@ impl<'a> FoldMapWriter<'a> {
consolidate_buffer_edits(&mut edits); consolidate_buffer_edits(&mut edits);
let edits = self.0.sync(buffer.clone(), edits); let edits = self.0.sync(buffer.clone(), edits);
let snapshot = Snapshot { let snapshot = FoldSnapshot {
transforms: self.0.transforms.lock().clone(), transforms: self.0.transforms.lock().clone(),
folds: self.0.folds.clone(), folds: self.0.folds.clone(),
buffer_snapshot: buffer, buffer_snapshot: buffer,
@ -145,7 +144,7 @@ impl<'a> FoldMapWriter<'a> {
pub fn unfold<T: ToOffset>( pub fn unfold<T: ToOffset>(
&mut self, &mut self,
ranges: impl IntoIterator<Item = Range<T>>, ranges: impl IntoIterator<Item = Range<T>>,
) -> (Snapshot, Vec<FoldEdit>) { ) -> (FoldSnapshot, Vec<FoldEdit>) {
let mut edits = Vec::new(); let mut edits = Vec::new();
let mut fold_ixs_to_delete = Vec::new(); let mut fold_ixs_to_delete = Vec::new();
let buffer = self.0.buffer.lock().clone(); let buffer = self.0.buffer.lock().clone();
@ -179,7 +178,7 @@ impl<'a> FoldMapWriter<'a> {
consolidate_buffer_edits(&mut edits); consolidate_buffer_edits(&mut edits);
let edits = self.0.sync(buffer.clone(), edits); let edits = self.0.sync(buffer.clone(), edits);
let snapshot = Snapshot { let snapshot = FoldSnapshot {
transforms: self.0.transforms.lock().clone(), transforms: self.0.transforms.lock().clone(),
folds: self.0.folds.clone(), folds: self.0.folds.clone(),
buffer_snapshot: buffer, buffer_snapshot: buffer,
@ -197,7 +196,7 @@ pub struct FoldMap {
} }
impl FoldMap { impl FoldMap {
pub fn new(buffer: BufferSnapshot) -> (Self, Snapshot) { pub fn new(buffer: BufferSnapshot) -> (Self, FoldSnapshot) {
let this = Self { let this = Self {
buffer: Mutex::new(buffer.clone()), buffer: Mutex::new(buffer.clone()),
folds: Default::default(), folds: Default::default(),
@ -214,7 +213,7 @@ impl FoldMap {
version: Default::default(), version: Default::default(),
}; };
let snapshot = Snapshot { let snapshot = FoldSnapshot {
transforms: this.transforms.lock().clone(), transforms: this.transforms.lock().clone(),
folds: this.folds.clone(), folds: this.folds.clone(),
buffer_snapshot: this.buffer.lock().clone(), buffer_snapshot: this.buffer.lock().clone(),
@ -227,10 +226,10 @@ impl FoldMap {
&self, &self,
buffer: BufferSnapshot, buffer: BufferSnapshot,
edits: Vec<Edit<usize>>, edits: Vec<Edit<usize>>,
) -> (Snapshot, Vec<FoldEdit>) { ) -> (FoldSnapshot, Vec<FoldEdit>) {
let edits = self.sync(buffer, edits); let edits = self.sync(buffer, edits);
self.check_invariants(); self.check_invariants();
let snapshot = Snapshot { let snapshot = FoldSnapshot {
transforms: self.transforms.lock().clone(), transforms: self.transforms.lock().clone(),
folds: self.folds.clone(), folds: self.folds.clone(),
buffer_snapshot: self.buffer.lock().clone(), buffer_snapshot: self.buffer.lock().clone(),
@ -243,7 +242,7 @@ impl FoldMap {
&mut self, &mut self,
buffer: BufferSnapshot, buffer: BufferSnapshot,
edits: Vec<Edit<usize>>, edits: Vec<Edit<usize>>,
) -> (FoldMapWriter, Snapshot, Vec<FoldEdit>) { ) -> (FoldMapWriter, FoldSnapshot, Vec<FoldEdit>) {
let (snapshot, edits) = self.read(buffer, edits); let (snapshot, edits) = self.read(buffer, edits);
(FoldMapWriter(self), snapshot, edits) (FoldMapWriter(self), snapshot, edits)
} }
@ -474,14 +473,14 @@ impl FoldMap {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct Snapshot { pub struct FoldSnapshot {
transforms: SumTree<Transform>, transforms: SumTree<Transform>,
folds: SumTree<Fold>, folds: SumTree<Fold>,
buffer_snapshot: language::Snapshot, buffer_snapshot: language::BufferSnapshot,
pub version: usize, pub version: usize,
} }
impl Snapshot { impl FoldSnapshot {
#[cfg(test)] #[cfg(test)]
pub fn text(&self) -> String { pub fn text(&self) -> String {
self.chunks(FoldOffset(0)..self.len(), None) self.chunks(FoldOffset(0)..self.len(), None)
@ -553,7 +552,7 @@ impl Snapshot {
(line_end - line_start) as u32 (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 { if start_row > self.transforms.summary().output.lines.row {
panic!("invalid display row {}", start_row); panic!("invalid display row {}", start_row);
} }
@ -561,7 +560,7 @@ impl Snapshot {
let fold_point = FoldPoint::new(start_row, 0); let fold_point = FoldPoint::new(start_row, 0);
let mut cursor = self.transforms.cursor(); let mut cursor = self.transforms.cursor();
cursor.seek(&fold_point, Bias::Left, &()); cursor.seek(&fold_point, Bias::Left, &());
BufferRows { fold_point, cursor } FoldBufferRows { fold_point, cursor }
} }
pub fn max_point(&self) -> FoldPoint { pub fn max_point(&self) -> FoldPoint {
@ -624,7 +623,7 @@ impl Snapshot {
&'a self, &'a self,
range: Range<FoldOffset>, range: Range<FoldOffset>,
theme: Option<&'a SyntaxTheme>, theme: Option<&'a SyntaxTheme>,
) -> Chunks<'a> { ) -> FoldChunks<'a> {
let mut transform_cursor = self.transforms.cursor::<(FoldOffset, usize)>(); let mut transform_cursor = self.transforms.cursor::<(FoldOffset, usize)>();
transform_cursor.seek(&range.end, Bias::Right, &()); transform_cursor.seek(&range.end, Bias::Right, &());
@ -635,7 +634,7 @@ impl Snapshot {
let overshoot = range.start.0 - transform_cursor.start().0 .0; let overshoot = range.start.0 - transform_cursor.start().0 .0;
let buffer_start = transform_cursor.start().1 + overshoot; let buffer_start = transform_cursor.start().1 + overshoot;
Chunks { FoldChunks {
transform_cursor, transform_cursor,
buffer_chunks: self.buffer_snapshot.chunks(buffer_start..buffer_end, theme), buffer_chunks: self.buffer_snapshot.chunks(buffer_start..buffer_end, theme),
buffer_chunk: None, buffer_chunk: None,
@ -700,7 +699,7 @@ impl Snapshot {
} }
fn intersecting_folds<'a, T>( fn intersecting_folds<'a, T>(
buffer: &'a text::Snapshot, buffer: &'a text::BufferSnapshot,
folds: &'a SumTree<Fold>, folds: &'a SumTree<Fold>,
range: Range<T>, range: Range<T>,
inclusive: bool, inclusive: bool,
@ -851,9 +850,9 @@ impl Default for FoldSummary {
} }
impl sum_tree::Summary 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 { if other.min_start.cmp(&self.min_start, buffer).unwrap() == Ordering::Less {
self.min_start = other.min_start.clone(); 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 { 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.start = summary.start.clone();
self.0.end = summary.end.clone(); self.0.end = summary.end.clone();
} }
} }
impl<'a> sum_tree::SeekTarget<'a, FoldSummary, Fold> for Fold { 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() self.0.cmp(&other.0, buffer).unwrap()
} }
} }
impl<'a> sum_tree::Dimension<'a, FoldSummary> for usize { 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; *self += summary.count;
} }
} }
pub struct BufferRows<'a> { pub struct FoldBufferRows<'a> {
cursor: Cursor<'a, Transform, (FoldPoint, Point)>, cursor: Cursor<'a, Transform, (FoldPoint, Point)>,
fold_point: FoldPoint, fold_point: FoldPoint,
} }
impl<'a> Iterator for BufferRows<'a> { impl<'a> Iterator for FoldBufferRows<'a> {
type Item = u32; type Item = u32;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -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)>, transform_cursor: Cursor<'a, Transform, (FoldOffset, usize)>,
buffer_chunks: language::Chunks<'a>, buffer_chunks: language::BufferChunks<'a>,
buffer_chunk: Option<(usize, Chunk<'a>)>, buffer_chunk: Option<(usize, Chunk<'a>)>,
buffer_offset: usize, buffer_offset: usize,
output_offset: usize, output_offset: usize,
max_output_offset: usize, max_output_offset: usize,
} }
impl<'a> Iterator for Chunks<'a> { impl<'a> Iterator for FoldChunks<'a> {
type Item = Chunk<'a>; type Item = Chunk<'a>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -1006,7 +1005,7 @@ impl<'a> sum_tree::Dimension<'a, TransformSummary> for FoldPoint {
pub struct FoldOffset(pub usize); pub struct FoldOffset(pub usize);
impl FoldOffset { impl FoldOffset {
pub fn to_point(&self, snapshot: &Snapshot) -> FoldPoint { pub fn to_point(&self, snapshot: &FoldSnapshot) -> FoldPoint {
let mut cursor = snapshot let mut cursor = snapshot
.transforms .transforms
.cursor::<(FoldOffset, TransformSummary)>(); .cursor::<(FoldOffset, TransformSummary)>();
@ -1520,7 +1519,10 @@ mod tests {
merged_ranges merged_ranges
} }
pub fn randomly_mutate(&mut self, rng: &mut impl Rng) -> Vec<(Snapshot, Vec<FoldEdit>)> { pub fn randomly_mutate(
&mut self,
rng: &mut impl Rng,
) -> Vec<(FoldSnapshot, Vec<FoldEdit>)> {
let mut snapshot_edits = Vec::new(); let mut snapshot_edits = Vec::new();
match rng.gen_range(0..=100) { match rng.gen_range(0..=100) {
0..=39 if !self.folds.is_empty() => { 0..=39 if !self.folds.is_empty() => {

View file

@ -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 language::{rope, Chunk};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::{cmp, mem, ops::Range}; use std::{cmp, mem, ops::Range};
@ -6,11 +6,11 @@ use sum_tree::Bias;
use text::Point; use text::Point;
use theme::SyntaxTheme; use theme::SyntaxTheme;
pub struct TabMap(Mutex<Snapshot>); pub struct TabMap(Mutex<TabSnapshot>);
impl TabMap { impl TabMap {
pub fn new(input: FoldSnapshot, tab_size: usize) -> (Self, Snapshot) { pub fn new(input: FoldSnapshot, tab_size: usize) -> (Self, TabSnapshot) {
let snapshot = Snapshot { let snapshot = TabSnapshot {
fold_snapshot: input, fold_snapshot: input,
tab_size, tab_size,
}; };
@ -21,10 +21,10 @@ impl TabMap {
&self, &self,
fold_snapshot: FoldSnapshot, fold_snapshot: FoldSnapshot,
mut fold_edits: Vec<FoldEdit>, mut fold_edits: Vec<FoldEdit>,
) -> (Snapshot, Vec<Edit>) { ) -> (TabSnapshot, Vec<Edit>) {
let mut old_snapshot = self.0.lock(); let mut old_snapshot = self.0.lock();
let max_offset = old_snapshot.fold_snapshot.len(); let max_offset = old_snapshot.fold_snapshot.len();
let new_snapshot = Snapshot { let new_snapshot = TabSnapshot {
fold_snapshot, fold_snapshot,
tab_size: old_snapshot.tab_size, tab_size: old_snapshot.tab_size,
}; };
@ -93,12 +93,12 @@ impl TabMap {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct Snapshot { pub struct TabSnapshot {
pub fold_snapshot: FoldSnapshot, pub fold_snapshot: FoldSnapshot,
pub tab_size: usize, pub tab_size: usize,
} }
impl Snapshot { impl TabSnapshot {
pub fn text_summary(&self) -> TextSummary { pub fn text_summary(&self) -> TextSummary {
self.text_summary_for_range(TabPoint::zero()..self.max_point()) self.text_summary_for_range(TabPoint::zero()..self.max_point())
} }
@ -155,7 +155,7 @@ impl Snapshot {
&'a self, &'a self,
range: Range<TabPoint>, range: Range<TabPoint>,
theme: Option<&'a SyntaxTheme>, theme: Option<&'a SyntaxTheme>,
) -> Chunks<'a> { ) -> TabChunks<'a> {
let (input_start, expanded_char_column, to_next_stop) = let (input_start, expanded_char_column, to_next_stop) =
self.to_fold_point(range.start, Bias::Left); self.to_fold_point(range.start, Bias::Left);
let input_start = input_start.to_offset(&self.fold_snapshot); let input_start = input_start.to_offset(&self.fold_snapshot);
@ -169,7 +169,7 @@ impl Snapshot {
to_next_stop to_next_stop
}; };
Chunks { TabChunks {
fold_chunks: self.fold_snapshot.chunks(input_start..input_end, theme), fold_chunks: self.fold_snapshot.chunks(input_start..input_end, theme),
column: expanded_char_column, column: expanded_char_column,
output_position: range.start.0, 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) self.fold_snapshot.buffer_rows(row)
} }
@ -380,8 +380,8 @@ impl<'a> std::ops::AddAssign<&'a Self> for TextSummary {
// Handles a tab width <= 16 // Handles a tab width <= 16
const SPACES: &'static str = " "; const SPACES: &'static str = " ";
pub struct Chunks<'a> { pub struct TabChunks<'a> {
fold_chunks: fold_map::Chunks<'a>, fold_chunks: fold_map::FoldChunks<'a>,
chunk: Chunk<'a>, chunk: Chunk<'a>,
column: usize, column: usize,
output_position: Point, output_position: Point,
@ -390,7 +390,7 @@ pub struct Chunks<'a> {
skip_leading_tab: bool, skip_leading_tab: bool,
} }
impl<'a> Iterator for Chunks<'a> { impl<'a> Iterator for TabChunks<'a> {
type Item = Chunk<'a>; type Item = Chunk<'a>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -457,9 +457,9 @@ mod tests {
#[test] #[test]
fn test_expand_tabs() { fn test_expand_tabs() {
assert_eq!(Snapshot::expand_tabs("\t".chars(), 0, 4), 0); assert_eq!(TabSnapshot::expand_tabs("\t".chars(), 0, 4), 0);
assert_eq!(Snapshot::expand_tabs("\t".chars(), 1, 4), 4); assert_eq!(TabSnapshot::expand_tabs("\t".chars(), 1, 4), 4);
assert_eq!(Snapshot::expand_tabs("\ta".chars(), 2, 4), 5); assert_eq!(TabSnapshot::expand_tabs("\ta".chars(), 2, 4), 5);
} }
#[gpui::test(iterations = 100)] #[gpui::test(iterations = 100)]

View file

@ -1,6 +1,6 @@
use super::{ use super::{
fold_map, fold_map,
tab_map::{self, Edit as TabEdit, Snapshot as TabSnapshot, TabPoint}, tab_map::{self, Edit as TabEdit, TabPoint, TabSnapshot},
}; };
use gpui::{ use gpui::{
fonts::FontId, text_layout::LineWrapper, Entity, ModelContext, ModelHandle, MutableAppContext, fonts::FontId, text_layout::LineWrapper, Entity, ModelContext, ModelHandle, MutableAppContext,
@ -18,7 +18,7 @@ pub use super::tab_map::TextSummary;
pub type Edit = text::Edit<u32>; pub type Edit = text::Edit<u32>;
pub struct WrapMap { pub struct WrapMap {
snapshot: Snapshot, snapshot: WrapSnapshot,
pending_edits: VecDeque<(TabSnapshot, Vec<TabEdit>)>, pending_edits: VecDeque<(TabSnapshot, Vec<TabEdit>)>,
interpolated_edits: Patch<u32>, interpolated_edits: Patch<u32>,
edits_since_sync: Patch<u32>, edits_since_sync: Patch<u32>,
@ -32,7 +32,7 @@ impl Entity for WrapMap {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct Snapshot { pub struct WrapSnapshot {
tab_snapshot: TabSnapshot, tab_snapshot: TabSnapshot,
transforms: SumTree<Transform>, transforms: SumTree<Transform>,
interpolated: bool, interpolated: bool,
@ -53,16 +53,16 @@ struct TransformSummary {
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct WrapPoint(pub super::Point); pub struct WrapPoint(pub super::Point);
pub struct Chunks<'a> { pub struct WrapChunks<'a> {
input_chunks: tab_map::Chunks<'a>, input_chunks: tab_map::TabChunks<'a>,
input_chunk: Chunk<'a>, input_chunk: Chunk<'a>,
output_position: WrapPoint, output_position: WrapPoint,
max_output_row: u32, max_output_row: u32,
transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>, transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>,
} }
pub struct BufferRows<'a> { pub struct WrapBufferRows<'a> {
input_buffer_rows: fold_map::BufferRows<'a>, input_buffer_rows: fold_map::FoldBufferRows<'a>,
input_buffer_row: u32, input_buffer_row: u32,
output_row: u32, output_row: u32,
soft_wrapped: bool, soft_wrapped: bool,
@ -77,7 +77,7 @@ impl WrapMap {
font_size: f32, font_size: f32,
wrap_width: Option<f32>, wrap_width: Option<f32>,
cx: &mut MutableAppContext, cx: &mut MutableAppContext,
) -> (ModelHandle<Self>, Snapshot) { ) -> (ModelHandle<Self>, WrapSnapshot) {
let handle = cx.add_model(|cx| { let handle = cx.add_model(|cx| {
let mut this = Self { let mut this = Self {
font: (font_id, font_size), font: (font_id, font_size),
@ -85,7 +85,7 @@ impl WrapMap {
pending_edits: Default::default(), pending_edits: Default::default(),
interpolated_edits: Default::default(), interpolated_edits: Default::default(),
edits_since_sync: Default::default(), edits_since_sync: Default::default(),
snapshot: Snapshot::new(tab_snapshot), snapshot: WrapSnapshot::new(tab_snapshot),
background_task: None, background_task: None,
}; };
this.set_wrap_width(wrap_width, cx); this.set_wrap_width(wrap_width, cx);
@ -106,7 +106,7 @@ impl WrapMap {
tab_snapshot: TabSnapshot, tab_snapshot: TabSnapshot,
edits: Vec<TabEdit>, edits: Vec<TabEdit>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> (Snapshot, Vec<Edit>) { ) -> (WrapSnapshot, Vec<Edit>) {
if self.wrap_width.is_some() { if self.wrap_width.is_some() {
self.pending_edits.push_back((tab_snapshot, edits)); self.pending_edits.push_back((tab_snapshot, edits));
self.flush_edits(cx); self.flush_edits(cx);
@ -291,7 +291,7 @@ impl WrapMap {
} }
} }
impl Snapshot { impl WrapSnapshot {
fn new(tab_snapshot: TabSnapshot) -> Self { fn new(tab_snapshot: TabSnapshot) -> Self {
let mut transforms = SumTree::new(); let mut transforms = SumTree::new();
let extent = tab_snapshot.text_summary(); let extent = tab_snapshot.text_summary();
@ -364,7 +364,7 @@ impl Snapshot {
let old_snapshot = mem::replace( let old_snapshot = mem::replace(
self, self,
Snapshot { WrapSnapshot {
tab_snapshot: new_tab_snapshot, tab_snapshot: new_tab_snapshot,
transforms: new_transforms, transforms: new_transforms,
interpolated: true, interpolated: true,
@ -513,7 +513,7 @@ impl Snapshot {
let old_snapshot = mem::replace( let old_snapshot = mem::replace(
self, self,
Snapshot { WrapSnapshot {
tab_snapshot: new_tab_snapshot, tab_snapshot: new_tab_snapshot,
transforms: new_transforms, transforms: new_transforms,
interpolated: false, interpolated: false,
@ -523,7 +523,7 @@ impl Snapshot {
old_snapshot.compute_edits(tab_edits, self) old_snapshot.compute_edits(tab_edits, self)
} }
fn compute_edits(&self, tab_edits: &[TabEdit], new_snapshot: &Snapshot) -> Patch<u32> { fn compute_edits(&self, tab_edits: &[TabEdit], new_snapshot: &WrapSnapshot) -> Patch<u32> {
let mut wrap_edits = Vec::new(); let mut wrap_edits = Vec::new();
let mut old_cursor = self.transforms.cursor::<TransformSummary>(); let mut old_cursor = self.transforms.cursor::<TransformSummary>();
let mut new_cursor = new_snapshot.transforms.cursor::<TransformSummary>(); let mut new_cursor = new_snapshot.transforms.cursor::<TransformSummary>();
@ -564,7 +564,11 @@ impl Snapshot {
.map(|h| h.text) .map(|h| h.text)
} }
pub fn chunks<'a>(&'a self, rows: Range<u32>, theme: Option<&'a SyntaxTheme>) -> Chunks<'a> { pub fn chunks<'a>(
&'a self,
rows: Range<u32>,
theme: Option<&'a SyntaxTheme>,
) -> WrapChunks<'a> {
let output_start = WrapPoint::new(rows.start, 0); let output_start = WrapPoint::new(rows.start, 0);
let output_end = WrapPoint::new(rows.end, 0); let output_end = WrapPoint::new(rows.end, 0);
let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>(); let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>();
@ -576,7 +580,7 @@ impl Snapshot {
let input_end = self let input_end = self
.to_tab_point(output_end) .to_tab_point(output_end)
.min(self.tab_snapshot.max_point()); .min(self.tab_snapshot.max_point());
Chunks { WrapChunks {
input_chunks: self.tab_snapshot.chunks(input_start..input_end, theme), input_chunks: self.tab_snapshot.chunks(input_start..input_end, theme),
input_chunk: Default::default(), input_chunk: Default::default(),
output_position: output_start, output_position: output_start,
@ -622,7 +626,7 @@ impl Snapshot {
self.transforms.summary().output.longest_row 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)>(); let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>();
transforms.seek(&WrapPoint::new(start_row, 0), Bias::Left, &()); transforms.seek(&WrapPoint::new(start_row, 0), Bias::Left, &());
let mut input_row = transforms.start().1.row(); 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 soft_wrapped = transforms.item().map_or(false, |t| !t.is_isomorphic());
let mut input_buffer_rows = self.tab_snapshot.buffer_rows(input_row); let mut input_buffer_rows = self.tab_snapshot.buffer_rows(input_row);
let input_buffer_row = input_buffer_rows.next().unwrap(); let input_buffer_row = input_buffer_rows.next().unwrap();
BufferRows { WrapBufferRows {
transforms, transforms,
input_buffer_row, input_buffer_row,
input_buffer_rows, 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>; type Item = Chunk<'a>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -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<u32>; type Item = Option<u32>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -1224,7 +1228,7 @@ mod tests {
} }
} }
impl Snapshot { impl WrapSnapshot {
pub fn text(&self) -> String { pub fn text(&self) -> String {
self.text_chunks(0).collect() self.text_chunks(0).collect()
} }

View file

@ -273,11 +273,11 @@ pub fn init(cx: &mut MutableAppContext, entry_openers: &mut Vec<Box<dyn EntryOpe
} }
trait SelectionExt { trait SelectionExt {
fn display_range(&self, map: &DisplayMapSnapshot) -> Range<DisplayPoint>; fn display_range(&self, map: &DisplaySnapshot) -> Range<DisplayPoint>;
fn spanned_rows( fn spanned_rows(
&self, &self,
include_end_if_at_line_start: bool, include_end_if_at_line_start: bool,
map: &DisplayMapSnapshot, map: &DisplaySnapshot,
) -> SpannedRows; ) -> SpannedRows;
} }
@ -371,9 +371,9 @@ pub struct Editor {
highlighted_row: Option<u32>, highlighted_row: Option<u32>,
} }
pub struct Snapshot { pub struct EditorSnapshot {
pub mode: EditorMode, pub mode: EditorMode,
pub display_snapshot: DisplayMapSnapshot, pub display_snapshot: DisplaySnapshot,
pub placeholder_text: Option<Arc<str>>, pub placeholder_text: Option<Arc<str>>,
is_focused: bool, is_focused: bool,
scroll_position: Vector2F, scroll_position: Vector2F,
@ -533,8 +533,8 @@ impl Editor {
&self.buffer &self.buffer
} }
pub fn snapshot(&mut self, cx: &mut MutableAppContext) -> Snapshot { pub fn snapshot(&mut self, cx: &mut MutableAppContext) -> EditorSnapshot {
Snapshot { EditorSnapshot {
mode: self.mode, mode: self.mode,
display_snapshot: self.display_map.update(cx, |map, cx| map.snapshot(cx)), display_snapshot: self.display_map.update(cx, |map, cx| map.snapshot(cx)),
scroll_position: self.scroll_position, scroll_position: self.scroll_position,
@ -986,7 +986,7 @@ impl Editor {
tail: DisplayPoint, tail: DisplayPoint,
head: DisplayPoint, head: DisplayPoint,
overshoot: u32, overshoot: u32,
display_map: &DisplayMapSnapshot, display_map: &DisplaySnapshot,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
let start_row = cmp::min(tail.row(), head.row()); let start_row = cmp::min(tail.row(), head.row());
@ -2966,7 +2966,7 @@ impl Editor {
fn build_columnar_selection( fn build_columnar_selection(
&mut self, &mut self,
display_map: &DisplayMapSnapshot, display_map: &DisplaySnapshot,
row: u32, row: u32,
columns: &Range<u32>, columns: &Range<u32>,
reversed: bool, reversed: bool,
@ -3271,7 +3271,7 @@ impl Editor {
self.unfold_ranges(ranges, cx); 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(); let max_point = display_map.max_point();
if display_row >= max_point.row() { if display_row >= max_point.row() {
false false
@ -3293,7 +3293,7 @@ impl Editor {
fn foldable_range_for_line( fn foldable_range_for_line(
&self, &self,
display_map: &DisplayMapSnapshot, display_map: &DisplaySnapshot,
start_row: u32, start_row: u32,
) -> Range<Point> { ) -> Range<Point> {
let max_point = display_map.max_point(); let max_point = display_map.max_point();
@ -3450,7 +3450,7 @@ impl Editor {
} }
} }
impl Snapshot { impl EditorSnapshot {
pub fn is_focused(&self) -> bool { pub fn is_focused(&self) -> bool {
self.is_focused self.is_focused
} }
@ -3468,8 +3468,8 @@ impl Snapshot {
} }
} }
impl Deref for Snapshot { impl Deref for EditorSnapshot {
type Target = DisplayMapSnapshot; type Target = DisplaySnapshot;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.display_snapshot &self.display_snapshot
@ -3525,7 +3525,7 @@ impl EditorSettings {
} }
fn compute_scroll_position( fn compute_scroll_position(
snapshot: &DisplayMapSnapshot, snapshot: &DisplaySnapshot,
mut scroll_position: Vector2F, mut scroll_position: Vector2F,
scroll_top_anchor: &Anchor, scroll_top_anchor: &Anchor,
) -> Vector2F { ) -> Vector2F {
@ -3606,7 +3606,7 @@ impl View for Editor {
} }
impl SelectionExt for Selection<Point> { impl SelectionExt for Selection<Point> {
fn display_range(&self, map: &DisplayMapSnapshot) -> Range<DisplayPoint> { fn display_range(&self, map: &DisplaySnapshot) -> Range<DisplayPoint> {
let start = self.start.to_display_point(map); let start = self.start.to_display_point(map);
let end = self.end.to_display_point(map); let end = self.end.to_display_point(map);
if self.reversed { if self.reversed {
@ -3619,7 +3619,7 @@ impl SelectionExt for Selection<Point> {
fn spanned_rows( fn spanned_rows(
&self, &self,
include_end_if_at_line_start: bool, include_end_if_at_line_start: bool,
map: &DisplayMapSnapshot, map: &DisplaySnapshot,
) -> SpannedRows { ) -> SpannedRows {
let display_start = self.start.to_display_point(map); let display_start = self.start.to_display_point(map);
let mut display_end = self.end.to_display_point(map); let mut display_end = self.end.to_display_point(map);

View file

@ -1,8 +1,8 @@
use crate::display_map::{BlockContext, ToDisplayPoint}; use crate::display_map::{BlockContext, ToDisplayPoint};
use super::{ use super::{
DisplayPoint, Editor, EditorMode, EditorSettings, EditorStyle, Input, Scroll, Select, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, Input, Scroll,
SelectPhase, Snapshot, SoftWrap, MAX_LINE_LEN, Select, SelectPhase, SoftWrap, MAX_LINE_LEN,
}; };
use clock::ReplicaId; use clock::ReplicaId;
use gpui::{ use gpui::{
@ -49,7 +49,7 @@ impl EditorElement {
self.view.upgrade(cx).unwrap().update(cx, f) 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)) 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 digit_count = (snapshot.buffer_row_count() as f32).log10().floor() as usize + 1;
let style = &self.settings.style; let style = &self.settings.style;
@ -458,7 +458,7 @@ impl EditorElement {
&self, &self,
rows: Range<u32>, rows: Range<u32>,
active_rows: &BTreeMap<u32, bool>, active_rows: &BTreeMap<u32, bool>,
snapshot: &Snapshot, snapshot: &EditorSnapshot,
cx: &LayoutContext, cx: &LayoutContext,
) -> Vec<Option<text_layout::Line>> { ) -> Vec<Option<text_layout::Line>> {
let style = &self.settings.style; let style = &self.settings.style;
@ -504,7 +504,7 @@ impl EditorElement {
fn layout_lines( fn layout_lines(
&mut self, &mut self,
mut rows: Range<u32>, mut rows: Range<u32>,
snapshot: &mut Snapshot, snapshot: &mut EditorSnapshot,
cx: &LayoutContext, cx: &LayoutContext,
) -> Vec<text_layout::Line> { ) -> Vec<text_layout::Line> {
rows.end = cmp::min(rows.end, snapshot.max_point().row() + 1); rows.end = cmp::min(rows.end, snapshot.max_point().row() + 1);
@ -623,7 +623,7 @@ impl EditorElement {
fn layout_blocks( fn layout_blocks(
&mut self, &mut self,
rows: Range<u32>, rows: Range<u32>,
snapshot: &Snapshot, snapshot: &EditorSnapshot,
text_width: f32, text_width: f32,
line_height: f32, line_height: f32,
style: &EditorStyle, style: &EditorStyle,
@ -923,7 +923,7 @@ pub struct LayoutState {
gutter_padding: f32, gutter_padding: f32,
text_size: Vector2F, text_size: Vector2F,
style: EditorStyle, style: EditorStyle,
snapshot: Snapshot, snapshot: EditorSnapshot,
active_rows: BTreeMap<u32, bool>, active_rows: BTreeMap<u32, bool>,
highlighted_row: Option<u32>, highlighted_row: Option<u32>,
line_layouts: Vec<text_layout::Line>, line_layouts: Vec<text_layout::Line>,
@ -961,7 +961,7 @@ impl LayoutState {
fn layout_line( fn layout_line(
row: u32, row: u32,
snapshot: &Snapshot, snapshot: &EditorSnapshot,
style: &EditorStyle, style: &EditorStyle,
layout_cache: &TextLayoutCache, layout_cache: &TextLayoutCache,
) -> text_layout::Line { ) -> text_layout::Line {
@ -998,7 +998,7 @@ pub struct PaintState {
impl PaintState { impl PaintState {
fn point_for_position( fn point_for_position(
&self, &self,
snapshot: &Snapshot, snapshot: &EditorSnapshot,
layout: &LayoutState, layout: &LayoutState,
position: Vector2F, position: Vector2F,
) -> (DisplayPoint, u32) { ) -> (DisplayPoint, u32) {

View file

@ -1,9 +1,9 @@
use super::{Bias, DisplayMapSnapshot, DisplayPoint, SelectionGoal, ToDisplayPoint}; use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
use anyhow::Result; use anyhow::Result;
use std::{cmp, ops::Range}; use std::{cmp, ops::Range};
use text::ToPoint; use text::ToPoint;
pub fn left(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> Result<DisplayPoint> { pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> Result<DisplayPoint> {
if point.column() > 0 { if point.column() > 0 {
*point.column_mut() -= 1; *point.column_mut() -= 1;
} else if point.row() > 0 { } else if point.row() > 0 {
@ -13,7 +13,7 @@ pub fn left(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> Result<Display
Ok(map.clip_point(point, Bias::Left)) Ok(map.clip_point(point, Bias::Left))
} }
pub fn right(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> Result<DisplayPoint> { pub fn right(map: &DisplaySnapshot, mut point: DisplayPoint) -> Result<DisplayPoint> {
let max_column = map.line_len(point.row()); let max_column = map.line_len(point.row());
if point.column() < max_column { if point.column() < max_column {
*point.column_mut() += 1; *point.column_mut() += 1;
@ -25,7 +25,7 @@ pub fn right(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> Result<Displa
} }
pub fn up( pub fn up(
map: &DisplayMapSnapshot, map: &DisplaySnapshot,
mut point: DisplayPoint, mut point: DisplayPoint,
goal: SelectionGoal, goal: SelectionGoal,
) -> Result<(DisplayPoint, SelectionGoal)> { ) -> Result<(DisplayPoint, SelectionGoal)> {
@ -61,7 +61,7 @@ pub fn up(
} }
pub fn down( pub fn down(
map: &DisplayMapSnapshot, map: &DisplaySnapshot,
mut point: DisplayPoint, mut point: DisplayPoint,
goal: SelectionGoal, goal: SelectionGoal,
) -> Result<(DisplayPoint, SelectionGoal)> { ) -> Result<(DisplayPoint, SelectionGoal)> {
@ -98,7 +98,7 @@ pub fn down(
} }
pub fn line_beginning( pub fn line_beginning(
map: &DisplayMapSnapshot, map: &DisplaySnapshot,
point: DisplayPoint, point: DisplayPoint,
toggle_indent: bool, toggle_indent: bool,
) -> DisplayPoint { ) -> 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())); let line_end = DisplayPoint::new(point.row(), map.line_len(point.row()));
map.clip_point(line_end, Bias::Left) 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; let mut line_start = 0;
if point.row() > 0 { if point.row() > 0 {
if let Some(indent) = map.soft_wrap_indent(point.row() - 1) { 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 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; let mut prev_char_kind = None;
for c in map.chars_at(point) { for c in map.chars_at(point) {
let char_kind = char_kind(c); let char_kind = char_kind(c);
@ -181,7 +181,7 @@ pub fn next_word_boundary(map: &DisplayMapSnapshot, mut point: DisplayPoint) ->
point 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 ix = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left);
let text = &map.buffer_snapshot; let text = &map.buffer_snapshot;
let next_char_kind = text.chars_at(ix).next().map(char_kind); 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)) prev_char_kind.zip(next_char_kind) == Some((CharKind::Word, CharKind::Word))
} }
pub fn surrounding_word(map: &DisplayMapSnapshot, point: DisplayPoint) -> Range<DisplayPoint> { pub fn surrounding_word(map: &DisplaySnapshot, point: DisplayPoint) -> Range<DisplayPoint> {
let mut start = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left); let mut start = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left);
let mut end = start; let mut end = start;

View file

@ -68,8 +68,8 @@ pub struct Buffer {
pub(crate) operations: Vec<Operation>, pub(crate) operations: Vec<Operation>,
} }
pub struct Snapshot { pub struct BufferSnapshot {
text: text::Snapshot, text: text::BufferSnapshot,
tree: Option<Tree>, tree: Option<Tree>,
diagnostics: AnchorRangeMultimap<Diagnostic>, diagnostics: AnchorRangeMultimap<Diagnostic>,
diagnostics_update_count: usize, diagnostics_update_count: usize,
@ -96,7 +96,7 @@ struct LanguageServerState {
#[derive(Clone)] #[derive(Clone)]
struct LanguageServerSnapshot { struct LanguageServerSnapshot {
buffer_snapshot: text::Snapshot, buffer_snapshot: text::BufferSnapshot,
version: usize, version: usize,
path: Arc<Path>, path: Arc<Path>,
} }
@ -172,7 +172,7 @@ struct SyntaxTree {
#[derive(Clone)] #[derive(Clone)]
struct AutoindentRequest { struct AutoindentRequest {
selection_set_ids: HashSet<SelectionSetId>, selection_set_ids: HashSet<SelectionSetId>,
before_edit: Snapshot, before_edit: BufferSnapshot,
edited: AnchorSet, edited: AnchorSet,
inserted: Option<AnchorRangeSet>, inserted: Option<AnchorRangeSet>,
} }
@ -185,7 +185,7 @@ struct IndentSuggestion {
struct TextProvider<'a>(&'a Rope); struct TextProvider<'a>(&'a Rope);
struct Highlights<'a> { struct BufferChunkHighlights<'a> {
captures: tree_sitter::QueryCaptures<'a, 'a, TextProvider<'a>>, captures: tree_sitter::QueryCaptures<'a, 'a, TextProvider<'a>>,
next_capture: Option<(tree_sitter::QueryMatch<'a, 'a>, usize)>, next_capture: Option<(tree_sitter::QueryMatch<'a, 'a>, usize)>,
stack: Vec<(usize, HighlightId)>, stack: Vec<(usize, HighlightId)>,
@ -194,7 +194,7 @@ struct Highlights<'a> {
_query_cursor: QueryCursorHandle, _query_cursor: QueryCursorHandle,
} }
pub struct Chunks<'a> { pub struct BufferChunks<'a> {
range: Range<usize>, range: Range<usize>,
chunks: rope::Chunks<'a>, chunks: rope::Chunks<'a>,
diagnostic_endpoints: Peekable<vec::IntoIter<DiagnosticEndpoint>>, diagnostic_endpoints: Peekable<vec::IntoIter<DiagnosticEndpoint>>,
@ -202,7 +202,7 @@ pub struct Chunks<'a> {
warning_depth: usize, warning_depth: usize,
information_depth: usize, information_depth: usize,
hint_depth: usize, hint_depth: usize,
highlights: Option<Highlights<'a>>, highlights: Option<BufferChunkHighlights<'a>>,
} }
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
@ -336,8 +336,8 @@ impl Buffer {
} }
} }
pub fn snapshot(&self) -> Snapshot { pub fn snapshot(&self) -> BufferSnapshot {
Snapshot { BufferSnapshot {
text: self.text.snapshot(), text: self.text.snapshot(),
tree: self.syntax_tree(), tree: self.syntax_tree(),
diagnostics: self.diagnostics.clone(), diagnostics: self.diagnostics.clone(),
@ -1512,7 +1512,7 @@ impl Deref for Buffer {
} }
} }
impl Snapshot { impl BufferSnapshot {
fn suggest_autoindents<'a>( fn suggest_autoindents<'a>(
&'a self, &'a self,
row_range: Range<u32>, row_range: Range<u32>,
@ -1626,7 +1626,7 @@ impl Snapshot {
&'a self, &'a self,
range: Range<T>, range: Range<T>,
theme: Option<&'a SyntaxTheme>, theme: Option<&'a SyntaxTheme>,
) -> Chunks<'a> { ) -> BufferChunks<'a> {
let range = range.start.to_offset(self)..range.end.to_offset(self); let range = range.start.to_offset(self)..range.end.to_offset(self);
let mut highlights = None; let mut highlights = None;
@ -1662,7 +1662,7 @@ impl Snapshot {
tree.root_node(), tree.root_node(),
TextProvider(self.text.as_rope()), TextProvider(self.text.as_rope()),
); );
highlights = Some(Highlights { highlights = Some(BufferChunkHighlights {
captures, captures,
next_capture: None, next_capture: None,
stack: Default::default(), stack: Default::default(),
@ -1676,7 +1676,7 @@ impl Snapshot {
let diagnostic_endpoints = diagnostic_endpoints.into_iter().peekable(); let diagnostic_endpoints = diagnostic_endpoints.into_iter().peekable();
let chunks = self.text.as_rope().chunks_in_range(range.clone()); let chunks = self.text.as_rope().chunks_in_range(range.clone());
Chunks { BufferChunks {
range, range,
chunks, chunks,
diagnostic_endpoints, diagnostic_endpoints,
@ -1703,7 +1703,7 @@ impl Snapshot {
} }
} }
impl Clone for Snapshot { impl Clone for BufferSnapshot {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
text: self.text.clone(), text: self.text.clone(),
@ -1717,8 +1717,8 @@ impl Clone for Snapshot {
} }
} }
impl Deref for Snapshot { impl Deref for BufferSnapshot {
type Target = text::Snapshot; type Target = text::BufferSnapshot;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.text &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) { pub fn seek(&mut self, offset: usize) {
self.range.start = offset; self.range.start = offset;
self.chunks.seek(self.range.start); 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>; type Item = Chunk<'a>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {

View file

@ -47,7 +47,7 @@ pub struct ExcerptProperties<'a, T> {
#[derive(Clone)] #[derive(Clone)]
struct Excerpt { struct Excerpt {
id: ExcerptId, id: ExcerptId,
buffer: buffer::Snapshot, buffer: buffer::BufferSnapshot,
range: Range<Anchor>, range: Range<Anchor>,
text_summary: TextSummary, text_summary: TextSummary,
header_height: u8, header_height: u8,
@ -66,7 +66,7 @@ pub struct Chunks<'a> {
range: Range<usize>, range: Range<usize>,
cursor: Cursor<'a, Excerpt, usize>, cursor: Cursor<'a, Excerpt, usize>,
header_height: u8, header_height: u8,
entry_chunks: Option<buffer::Chunks<'a>>, entry_chunks: Option<buffer::BufferChunks<'a>>,
theme: Option<&'a SyntaxTheme>, theme: Option<&'a SyntaxTheme>,
} }
@ -339,7 +339,7 @@ impl Snapshot {
impl Excerpt { impl Excerpt {
fn new( fn new(
id: ExcerptId, id: ExcerptId,
buffer: buffer::Snapshot, buffer: buffer::BufferSnapshot,
range: Range<Anchor>, range: Range<Anchor>,
header_height: u8, header_height: u8,
) -> Self { ) -> Self {

View file

@ -1,4 +1,4 @@
use crate::{rope::TextDimension, Snapshot}; use crate::{rope::TextDimension, BufferSnapshot};
use super::{Buffer, FromAnchor, FullOffset, Point, ToOffset}; use super::{Buffer, FromAnchor, FullOffset, Point, ToOffset};
use anyhow::Result; use anyhow::Result;
@ -83,7 +83,7 @@ impl Anchor {
} }
} }
pub fn cmp<'a>(&self, other: &Anchor, buffer: &Snapshot) -> Result<Ordering> { pub fn cmp<'a>(&self, other: &Anchor, buffer: &BufferSnapshot) -> Result<Ordering> {
if self == other { if self == other {
return Ok(Ordering::Equal); 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 where
D: TextDimension<'a>, D: TextDimension<'a>,
{ {
@ -132,7 +132,10 @@ impl<T> AnchorMap<T> {
self.entries.len() self.entries.len()
} }
pub fn iter<'a, D>(&'a self, snapshot: &'a Snapshot) -> impl Iterator<Item = (D, &'a T)> + 'a pub fn iter<'a, D>(
&'a self,
snapshot: &'a BufferSnapshot,
) -> impl Iterator<Item = (D, &'a T)> + 'a
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
{ {
@ -155,7 +158,7 @@ impl AnchorSet {
self.0.len() self.0.len()
} }
pub fn iter<'a, D>(&'a self, content: &'a Snapshot) -> impl Iterator<Item = D> + 'a pub fn iter<'a, D>(&'a self, content: &'a BufferSnapshot) -> impl Iterator<Item = D> + 'a
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
{ {
@ -188,7 +191,7 @@ impl<T> AnchorRangeMap<T> {
pub fn ranges<'a, D>( pub fn ranges<'a, D>(
&'a self, &'a self,
content: &'a Snapshot, content: &'a BufferSnapshot,
) -> impl Iterator<Item = (Range<D>, &'a T)> + 'a ) -> impl Iterator<Item = (Range<D>, &'a T)> + 'a
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
@ -206,7 +209,7 @@ impl<T> AnchorRangeMap<T> {
pub fn intersecting_ranges<'a, D, I>( pub fn intersecting_ranges<'a, D, I>(
&'a self, &'a self,
range: Range<(I, Bias)>, range: Range<(I, Bias)>,
content: &'a Snapshot, content: &'a BufferSnapshot,
) -> impl Iterator<Item = (Range<D>, &'a T)> + 'a ) -> impl Iterator<Item = (Range<D>, &'a T)> + 'a
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
@ -243,7 +246,7 @@ impl<T> AnchorRangeMap<T> {
pub fn min_by_key<'a, D, F, K>( pub fn min_by_key<'a, D, F, K>(
&self, &self,
content: &'a Snapshot, content: &'a BufferSnapshot,
mut extract_key: F, mut extract_key: F,
) -> Option<(Range<D>, &T)> ) -> Option<(Range<D>, &T)>
where where
@ -259,7 +262,7 @@ impl<T> AnchorRangeMap<T> {
pub fn max_by_key<'a, D, F, K>( pub fn max_by_key<'a, D, F, K>(
&self, &self,
content: &'a Snapshot, content: &'a BufferSnapshot,
mut extract_key: F, mut extract_key: F,
) -> Option<(Range<D>, &T)> ) -> Option<(Range<D>, &T)>
where where
@ -273,7 +276,11 @@ impl<T> AnchorRangeMap<T> {
.map(|(range, value)| (self.resolve_range(range, &content), value)) .map(|(range, value)| (self.resolve_range(range, &content), value))
} }
fn resolve_range<'a, D>(&self, range: &Range<FullOffset>, content: &'a Snapshot) -> Range<D> fn resolve_range<'a, D>(
&self,
range: &Range<FullOffset>,
content: &'a BufferSnapshot,
) -> Range<D>
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
{ {
@ -330,7 +337,10 @@ impl AnchorRangeSet {
self.0.version() self.0.version()
} }
pub fn ranges<'a, D>(&'a self, content: &'a Snapshot) -> impl 'a + Iterator<Item = Range<Point>> pub fn ranges<'a, D>(
&'a self,
content: &'a BufferSnapshot,
) -> impl 'a + Iterator<Item = Range<Point>>
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
{ {
@ -357,7 +367,7 @@ impl<T: Clone> AnchorRangeMultimap<T> {
pub fn intersecting_ranges<'a, I, O>( pub fn intersecting_ranges<'a, I, O>(
&'a self, &'a self,
range: Range<I>, range: Range<I>,
content: &'a Snapshot, content: &'a BufferSnapshot,
inclusive: bool, inclusive: bool,
) -> impl Iterator<Item = (usize, Range<O>, &T)> + 'a ) -> impl Iterator<Item = (usize, Range<O>, &T)> + 'a
where where
@ -451,7 +461,7 @@ impl<T: Clone> AnchorRangeMultimap<T> {
pub fn filter<'a, O, F>( pub fn filter<'a, O, F>(
&'a self, &'a self,
content: &'a Snapshot, content: &'a BufferSnapshot,
mut f: F, mut f: F,
) -> impl 'a + Iterator<Item = (usize, Range<O>, &T)> ) -> impl 'a + Iterator<Item = (usize, Range<O>, &T)>
where where
@ -560,19 +570,19 @@ impl<'a> sum_tree::SeekTarget<'a, AnchorRangeMultimapSummary, FullOffsetRange> f
} }
pub trait AnchorRangeExt { pub trait AnchorRangeExt {
fn cmp(&self, b: &Range<Anchor>, buffer: &Snapshot) -> Result<Ordering>; fn cmp(&self, b: &Range<Anchor>, buffer: &BufferSnapshot) -> Result<Ordering>;
fn to_offset(&self, content: &Snapshot) -> Range<usize>; fn to_offset(&self, content: &BufferSnapshot) -> Range<usize>;
} }
impl AnchorRangeExt for Range<Anchor> { impl AnchorRangeExt for Range<Anchor> {
fn cmp(&self, other: &Range<Anchor>, buffer: &Snapshot) -> Result<Ordering> { fn cmp(&self, other: &Range<Anchor>, buffer: &BufferSnapshot) -> Result<Ordering> {
Ok(match self.start.cmp(&other.start, buffer)? { Ok(match self.start.cmp(&other.start, buffer)? {
Ordering::Equal => other.end.cmp(&self.end, buffer)?, Ordering::Equal => other.end.cmp(&self.end, buffer)?,
ord @ _ => ord, ord @ _ => ord,
}) })
} }
fn to_offset(&self, content: &Snapshot) -> Range<usize> { fn to_offset(&self, content: &BufferSnapshot) -> Range<usize> {
self.start.to_offset(&content)..self.end.to_offset(&content) self.start.to_offset(&content)..self.end.to_offset(&content)
} }
} }

View file

@ -1,6 +1,6 @@
use sum_tree::Bias; use sum_tree::Bias;
use crate::{rope::TextDimension, Snapshot}; use crate::{rope::TextDimension, BufferSnapshot};
use super::{AnchorRangeMap, Buffer, Point, ToOffset, ToPoint}; use super::{AnchorRangeMap, Buffer, Point, ToOffset, ToPoint};
use std::{cmp::Ordering, ops::Range, sync::Arc}; use std::{cmp::Ordering, ops::Range, sync::Arc};
@ -105,7 +105,7 @@ impl SelectionSet {
pub fn selections<'a, D>( pub fn selections<'a, D>(
&'a self, &'a self,
content: &'a Snapshot, content: &'a BufferSnapshot,
) -> impl 'a + Iterator<Item = Selection<D>> ) -> impl 'a + Iterator<Item = Selection<D>>
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
@ -124,7 +124,7 @@ impl SelectionSet {
pub fn intersecting_selections<'a, D, I>( pub fn intersecting_selections<'a, D, I>(
&'a self, &'a self,
range: Range<(I, Bias)>, range: Range<(I, Bias)>,
content: &'a Snapshot, content: &'a BufferSnapshot,
) -> impl 'a + Iterator<Item = Selection<D>> ) -> impl 'a + Iterator<Item = Selection<D>>
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
@ -141,7 +141,7 @@ impl SelectionSet {
}) })
} }
pub fn oldest_selection<'a, D>(&'a self, content: &'a Snapshot) -> Option<Selection<D>> pub fn oldest_selection<'a, D>(&'a self, content: &'a BufferSnapshot) -> Option<Selection<D>>
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
{ {
@ -156,7 +156,7 @@ impl SelectionSet {
}) })
} }
pub fn newest_selection<'a, D>(&'a self, content: &'a Snapshot) -> Option<Selection<D>> pub fn newest_selection<'a, D>(&'a self, content: &'a BufferSnapshot) -> Option<Selection<D>>
where where
D: 'a + TextDimension<'a>, D: 'a + TextDimension<'a>,
{ {

View file

@ -37,7 +37,7 @@ pub use sum_tree::Bias;
use sum_tree::{FilterCursor, SumTree}; use sum_tree::{FilterCursor, SumTree};
pub struct Buffer { pub struct Buffer {
snapshot: Snapshot, snapshot: BufferSnapshot,
last_edit: clock::Local, last_edit: clock::Local,
history: History, history: History,
selections: HashMap<SelectionSetId, SelectionSet>, selections: HashMap<SelectionSetId, SelectionSet>,
@ -51,7 +51,7 @@ pub struct Buffer {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Snapshot { pub struct BufferSnapshot {
visible_text: Rope, visible_text: Rope,
deleted_text: Rope, deleted_text: Rope,
undo_map: UndoMap, undo_map: UndoMap,
@ -473,7 +473,7 @@ impl Buffer {
} }
Buffer { Buffer {
snapshot: Snapshot { snapshot: BufferSnapshot {
visible_text, visible_text,
deleted_text: Rope::new(), deleted_text: Rope::new(),
fragments, fragments,
@ -497,8 +497,8 @@ impl Buffer {
self.version.clone() self.version.clone()
} }
pub fn snapshot(&self) -> Snapshot { pub fn snapshot(&self) -> BufferSnapshot {
Snapshot { BufferSnapshot {
visible_text: self.visible_text.clone(), visible_text: self.visible_text.clone(),
deleted_text: self.deleted_text.clone(), deleted_text: self.deleted_text.clone(),
undo_map: self.undo_map.clone(), undo_map: self.undo_map.clone(),
@ -1476,14 +1476,14 @@ impl Buffer {
} }
impl Deref for Buffer { impl Deref for Buffer {
type Target = Snapshot; type Target = BufferSnapshot;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.snapshot &self.snapshot
} }
} }
impl Snapshot { impl BufferSnapshot {
pub fn as_rope(&self) -> &Rope { pub fn as_rope(&self) -> &Rope {
&self.visible_text &self.visible_text
} }
@ -2254,9 +2254,9 @@ impl Operation {
} }
pub trait ToOffset { 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 offset = self.to_offset(&content);
let mut cursor = content.fragments.cursor::<FragmentTextSummary>(); let mut cursor = content.fragments.cursor::<FragmentTextSummary>();
cursor.seek(&offset, bias, &None); cursor.seek(&offset, bias, &None);
@ -2265,30 +2265,30 @@ pub trait ToOffset {
} }
impl ToOffset for Point { 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) content.visible_text.point_to_offset(*self)
} }
} }
impl ToOffset for PointUtf16 { 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) content.visible_text.point_utf16_to_offset(*self)
} }
} }
impl ToOffset for usize { 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"); assert!(*self <= content.len(), "offset is out of range");
*self *self
} }
} }
impl ToOffset for Anchor { 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) 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 { if content.version == self.version {
self.full_offset self.full_offset
} else { } else {
@ -2312,45 +2312,45 @@ impl ToOffset for Anchor {
} }
impl<'a> ToOffset for &'a 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) content.summary_for_anchor(self)
} }
} }
pub trait ToPoint { pub trait ToPoint {
fn to_point<'a>(&self, content: &Snapshot) -> Point; fn to_point<'a>(&self, content: &BufferSnapshot) -> Point;
} }
impl ToPoint for Anchor { 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) content.summary_for_anchor(self)
} }
} }
impl ToPoint for usize { 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) content.visible_text.offset_to_point(*self)
} }
} }
impl ToPoint for Point { impl ToPoint for Point {
fn to_point<'a>(&self, _: &Snapshot) -> Point { fn to_point<'a>(&self, _: &BufferSnapshot) -> Point {
*self *self
} }
} }
pub trait FromAnchor { pub trait FromAnchor {
fn from_anchor(anchor: &Anchor, content: &Snapshot) -> Self; fn from_anchor(anchor: &Anchor, content: &BufferSnapshot) -> Self;
} }
impl FromAnchor for Point { impl FromAnchor for Point {
fn from_anchor(anchor: &Anchor, content: &Snapshot) -> Self { fn from_anchor(anchor: &Anchor, content: &BufferSnapshot) -> Self {
anchor.to_point(content) anchor.to_point(content)
} }
} }
impl FromAnchor for usize { impl FromAnchor for usize {
fn from_anchor(anchor: &Anchor, content: &Snapshot) -> Self { fn from_anchor(anchor: &Anchor, content: &BufferSnapshot) -> Self {
anchor.to_offset(content) anchor.to_offset(content)
} }
} }