Consistency in prefix/suffix/signature of UTF16 point to point conversion

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Julia 2022-11-23 13:52:18 -05:00
parent 03cfd23ac5
commit 55ca085d7d
2 changed files with 11 additions and 11 deletions

View file

@ -351,16 +351,16 @@ impl Rope {
.map_or(0, |chunk| chunk.point_utf16_to_offset(overshoot, clip)) .map_or(0, |chunk| chunk.point_utf16_to_offset(overshoot, clip))
} }
pub fn point_utf16_to_point_clipped(&self, point: PointUtf16) -> Point { pub fn unclipped_point_utf16_to_point(&self, point: Unclipped<PointUtf16>) -> Point {
if point >= self.summary().lines_utf16() { if point.0 >= self.summary().lines_utf16() {
return self.summary().lines; return self.summary().lines;
} }
let mut cursor = self.chunks.cursor::<(PointUtf16, Point)>(); let mut cursor = self.chunks.cursor::<(PointUtf16, Point)>();
cursor.seek(&point, Bias::Left, &()); cursor.seek(&point.0, Bias::Left, &());
let overshoot = point - cursor.start().0; let overshoot = Unclipped(point.0 - cursor.start().0);
cursor.start().1 cursor.start().1
+ cursor.item().map_or(Point::zero(), |chunk| { + cursor.item().map_or(Point::zero(), |chunk| {
chunk.point_utf16_to_point_clipped(overshoot) chunk.unclipped_point_utf16_to_point(overshoot)
}) })
} }
@ -830,16 +830,16 @@ impl Chunk {
offset offset
} }
fn point_utf16_to_point_clipped(&self, target: PointUtf16) -> Point { fn unclipped_point_utf16_to_point(&self, target: Unclipped<PointUtf16>) -> Point {
let mut point = Point::zero(); let mut point = Point::zero();
let mut point_utf16 = PointUtf16::zero(); let mut point_utf16 = PointUtf16::zero();
for ch in self.0.chars() { for ch in self.0.chars() {
if point_utf16 == target { if point_utf16 == target.0 {
break; break;
} }
if point_utf16 > target { if point_utf16 > target.0 {
// If the point is past the end of a line or inside of a code point, // If the point is past the end of a line or inside of a code point,
// return the last valid point before the target. // return the last valid point before the target.
return point; return point;

View file

@ -1598,8 +1598,8 @@ impl BufferSnapshot {
self.visible_text.unclipped_point_utf16_to_offset(point) self.visible_text.unclipped_point_utf16_to_offset(point)
} }
pub fn point_utf16_to_point_clipped(&self, point: PointUtf16) -> Point { pub fn unclipped_point_utf16_to_point(&self, point: Unclipped<PointUtf16>) -> Point {
self.visible_text.point_utf16_to_point_clipped(point) self.visible_text.unclipped_point_utf16_to_point(point)
} }
pub fn offset_utf16_to_offset(&self, offset: OffsetUtf16) -> usize { pub fn offset_utf16_to_offset(&self, offset: OffsetUtf16) -> usize {
@ -2421,7 +2421,7 @@ impl ToPoint for Point {
impl ToPoint for Unclipped<PointUtf16> { impl ToPoint for Unclipped<PointUtf16> {
fn to_point<'a>(&self, snapshot: &BufferSnapshot) -> Point { fn to_point<'a>(&self, snapshot: &BufferSnapshot) -> Point {
snapshot.point_utf16_to_point_clipped(self.0) snapshot.unclipped_point_utf16_to_point(*self)
} }
} }