diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 7206dbb199..4575e9ce5e 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -55,7 +55,7 @@ use link_go_to_definition::{ }; pub use multi_buffer::{ Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset, - ToOffsetClamped, ToPoint, + ToOffsetClipped, ToPoint, }; use multi_buffer::{MultiBufferChunks, ToOffsetUtf16}; use ordered_float::OrderedFloat; diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 70645bbfe0..aa25b47680 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -72,8 +72,8 @@ pub trait ToOffset: 'static + fmt::Debug { fn to_offset(&self, snapshot: &MultiBufferSnapshot) -> usize; } -pub trait ToOffsetClamped: 'static + fmt::Debug { - fn to_offset_clamped(&self, snapshot: &MultiBufferSnapshot) -> usize; +pub trait ToOffsetClipped: 'static + fmt::Debug { + fn to_offset_clipped(&self, snapshot: &MultiBufferSnapshot) -> usize; } pub trait ToOffsetUtf16: 'static + fmt::Debug { @@ -1949,9 +1949,9 @@ impl MultiBufferSnapshot { } } - pub fn point_utf16_to_offset_clamped(&self, point: PointUtf16) -> usize { + pub fn point_utf16_to_offset_clipped(&self, point: PointUtf16) -> usize { if let Some((_, _, buffer)) = self.as_singleton() { - return buffer.point_utf16_to_offset_clamped(point); + return buffer.point_utf16_to_offset_clipped(point); } let mut cursor = self.excerpts.cursor::<(PointUtf16, usize)>(); @@ -1965,7 +1965,7 @@ impl MultiBufferSnapshot { .offset_to_point_utf16(excerpt.range.context.start.to_offset(&excerpt.buffer)); let buffer_offset = excerpt .buffer - .point_utf16_to_offset_clamped(excerpt_start_point + overshoot); + .point_utf16_to_offset_clipped(excerpt_start_point + overshoot); *start_offset + (buffer_offset - excerpt_start_offset) } else { self.excerpts.summary().text.len @@ -3291,9 +3291,9 @@ impl ToOffset for OffsetUtf16 { } } -impl ToOffsetClamped for PointUtf16 { - fn to_offset_clamped<'a>(&self, snapshot: &MultiBufferSnapshot) -> usize { - snapshot.point_utf16_to_offset_clamped(*self) +impl ToOffsetClipped for PointUtf16 { + fn to_offset_clipped<'a>(&self, snapshot: &MultiBufferSnapshot) -> usize { + snapshot.point_utf16_to_offset_clipped(*self) } } diff --git a/crates/editor/src/selections_collection.rs b/crates/editor/src/selections_collection.rs index 01e38d269e..14026d9f4e 100644 --- a/crates/editor/src/selections_collection.rs +++ b/crates/editor/src/selections_collection.rs @@ -14,7 +14,7 @@ use util::post_inc; use crate::{ display_map::{DisplayMap, DisplaySnapshot, ToDisplayPoint}, Anchor, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode, ToOffset, - ToOffsetClamped, + ToOffsetClipped, }; #[derive(Clone)] @@ -551,14 +551,14 @@ impl<'a> MutableSelectionsCollection<'a> { self.select_offset_ranges(ranges); } - pub fn select_clamped_ranges(&mut self, ranges: I) + pub fn select_clipped_ranges(&mut self, ranges: I) where I: IntoIterator>, - T: ToOffsetClamped, + T: ToOffsetClipped, { let buffer = self.buffer.read(self.cx).snapshot(self.cx); let ranges = ranges.into_iter().map(|range| { - range.start.to_offset_clamped(&buffer)..range.end.to_offset_clamped(&buffer) + range.start.to_offset_clipped(&buffer)..range.end.to_offset_clipped(&buffer) }); self.select_offset_ranges(ranges); } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 2036ef3cd8..e1339ba434 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -25,7 +25,7 @@ use language::{ range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, CachedLspAdapter, CharKind, CodeAction, CodeLabel, Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Event as BufferEvent, File as _, Language, LanguageRegistry, LanguageServerName, LocalFile, OffsetRangeExt, - Operation, Patch, PointUtf16, TextBufferSnapshot, ToOffset, ToOffsetClamped, ToPointUtf16, + Operation, Patch, PointUtf16, TextBufferSnapshot, ToOffset, ToOffsetClipped, ToPointUtf16, Transaction, }; use lsp::{ @@ -3369,7 +3369,7 @@ impl Project { } let Range { start, end } = range_for_token .get_or_insert_with(|| { - let offset = position.to_offset_clamped(&snapshot); + let offset = position.to_offset_clipped(&snapshot); let (range, kind) = snapshot.surrounding_word(offset); if kind == Some(CharKind::Word) { range @@ -5743,7 +5743,7 @@ impl Project { // we can identify the changes more precisely, preserving the locations // of any anchors positioned in the unchanged regions. if range.end.row > range.start.row { - let mut offset = range.start.to_offset_clamped(&snapshot); + let mut offset = range.start.to_offset_clipped(&snapshot); let old_text = snapshot.text_for_clamped_range(range).collect::(); let diff = TextDiff::from_lines(old_text.as_str(), &new_text); diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rs index 60623e99ca..eb755d2d2f 100644 --- a/crates/project_symbols/src/project_symbols.rs +++ b/crates/project_symbols/src/project_symbols.rs @@ -151,7 +151,7 @@ impl ProjectSymbolsView { let editor = workspace.open_project_item::(buffer, cx); editor.update(cx, |editor, cx| { editor.change_selections(Some(Autoscroll::center()), cx, |s| { - s.select_clamped_ranges([position..position]) + s.select_clipped_ranges([position..position]) }); }); }); diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rs index ca1f35bb13..9b52815ae3 100644 --- a/crates/rope/src/rope.rs +++ b/crates/rope/src/rope.rs @@ -259,7 +259,7 @@ impl Rope { .map_or(0, |chunk| chunk.point_to_offset(overshoot)) } - pub fn point_utf16_to_offset_clamped(&self, point: PointUtf16) -> usize { + pub fn point_utf16_to_offset_clipped(&self, point: PointUtf16) -> usize { if point >= self.summary().lines_utf16() { return self.summary().len; } @@ -269,7 +269,7 @@ impl Rope { cursor.start().1 + cursor .item() - .map_or(0, |chunk| chunk.point_utf16_to_offset_clamped(overshoot)) + .map_or(0, |chunk| chunk.point_utf16_to_offset_clipped(overshoot)) } pub fn point_utf16_to_point(&self, point: PointUtf16) -> Point { @@ -711,7 +711,7 @@ impl Chunk { point_utf16 } - fn point_utf16_to_offset_clamped(&self, target: PointUtf16) -> usize { + fn point_utf16_to_offset_clipped(&self, target: PointUtf16) -> usize { let mut offset = 0; let mut point = PointUtf16::new(0, 0); @@ -1210,7 +1210,7 @@ mod tests { point ); assert_eq!( - actual.point_utf16_to_offset_clamped(point_utf16), + actual.point_utf16_to_offset_clipped(point_utf16), ix, "point_utf16_to_offset({:?})", point_utf16 @@ -1251,8 +1251,8 @@ mod tests { let right_point = actual.clip_point_utf16(point_utf16, Bias::Right); assert!(right_point >= left_point); // Ensure translating UTF-16 points to offsets doesn't panic. - actual.point_utf16_to_offset_clamped(left_point); - actual.point_utf16_to_offset_clamped(right_point); + actual.point_utf16_to_offset_clipped(left_point); + actual.point_utf16_to_offset_clipped(right_point); offset_utf16.0 += 1; if unit == b'\n' as u16 { diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs index aec46b03cf..8cdf087b53 100644 --- a/crates/text/src/text.rs +++ b/crates/text/src/text.rs @@ -1590,8 +1590,8 @@ impl BufferSnapshot { self.visible_text.point_to_offset(point) } - pub fn point_utf16_to_offset_clamped(&self, point: PointUtf16) -> usize { - self.visible_text.point_utf16_to_offset_clamped(point) + pub fn point_utf16_to_offset_clipped(&self, point: PointUtf16) -> usize { + self.visible_text.point_utf16_to_offset_clipped(point) } pub fn point_utf16_to_point(&self, point: PointUtf16) -> Point { @@ -1649,9 +1649,9 @@ impl BufferSnapshot { self.visible_text.chunks_in_range(start..end) } - pub fn text_for_clamped_range(&self, range: Range) -> Chunks<'_> { - let start = range.start.to_offset_clamped(self); - let end = range.end.to_offset_clamped(self); + pub fn text_for_clamped_range(&self, range: Range) -> Chunks<'_> { + let start = range.start.to_offset_clipped(self); + let end = range.end.to_offset_clipped(self); self.visible_text.chunks_in_range(start..end) } @@ -1804,16 +1804,16 @@ impl BufferSnapshot { self.anchor_at(position, Bias::Left) } - pub fn clamped_anchor_before(&self, position: T) -> Anchor { - self.anchor_at_offset(position.to_offset_clamped(self), Bias::Left) + pub fn clamped_anchor_before(&self, position: T) -> Anchor { + self.anchor_at_offset(position.to_offset_clipped(self), Bias::Left) } pub fn anchor_after(&self, position: T) -> Anchor { self.anchor_at(position, Bias::Right) } - pub fn clamped_anchor_after(&self, position: T) -> Anchor { - self.anchor_at_offset(position.to_offset_clamped(self), Bias::Right) + pub fn clamped_anchor_after(&self, position: T) -> Anchor { + self.anchor_at_offset(position.to_offset_clipped(self), Bias::Right) } pub fn anchor_at(&self, position: T, bias: Bias) -> Anchor { @@ -2395,13 +2395,13 @@ impl<'a, T: ToOffset> ToOffset for &'a T { } } -pub trait ToOffsetClamped { - fn to_offset_clamped(&self, snapshot: &BufferSnapshot) -> usize; +pub trait ToOffsetClipped { + fn to_offset_clipped(&self, snapshot: &BufferSnapshot) -> usize; } -impl ToOffsetClamped for PointUtf16 { - fn to_offset_clamped<'a>(&self, snapshot: &BufferSnapshot) -> usize { - snapshot.point_utf16_to_offset_clamped(*self) +impl ToOffsetClipped for PointUtf16 { + fn to_offset_clipped<'a>(&self, snapshot: &BufferSnapshot) -> usize { + snapshot.point_utf16_to_offset_clipped(*self) } }