Clamp UTF-16 to point conversions

This commit is contained in:
Julia 2022-11-16 13:29:26 -05:00
parent bb32599ded
commit 074e3cfbd6
6 changed files with 65 additions and 45 deletions

View file

@ -1590,12 +1590,8 @@ impl BufferSnapshot {
self.visible_text.point_to_offset(point)
}
pub fn point_utf16_to_offset(&self, point: PointUtf16) -> usize {
self.visible_text.point_utf16_to_offset(point, false)
}
pub fn point_utf16_to_offset_clamped(&self, point: PointUtf16) -> usize {
self.visible_text.point_utf16_to_offset(point, true)
self.visible_text.point_utf16_to_offset_clamped(point)
}
pub fn point_utf16_to_point(&self, point: PointUtf16) -> Point {
@ -2425,18 +2421,22 @@ impl ToPoint for usize {
}
}
impl ToPoint for PointUtf16 {
fn to_point<'a>(&self, snapshot: &BufferSnapshot) -> Point {
snapshot.point_utf16_to_point(*self)
}
}
impl ToPoint for Point {
fn to_point<'a>(&self, _: &BufferSnapshot) -> Point {
*self
}
}
pub trait ToPointClamped {
fn to_point_clamped(&self, snapshot: &BufferSnapshot) -> Point;
}
impl ToPointClamped for PointUtf16 {
fn to_point_clamped<'a>(&self, snapshot: &BufferSnapshot) -> Point {
snapshot.point_utf16_to_point(*self)
}
}
pub trait ToPointUtf16 {
fn to_point_utf16(&self, snapshot: &BufferSnapshot) -> PointUtf16;
}