Add a ToPointUtf16 trait in text and multibuffer

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-02-04 17:35:37 -08:00
parent 16acbd2123
commit 4900019e9b
5 changed files with 144 additions and 18 deletions

View file

@ -1512,6 +1512,10 @@ impl BufferSnapshot {
self.visible_text.offset_to_point_utf16(offset)
}
pub fn point_to_point_utf16(&self, point: Point) -> PointUtf16 {
self.visible_text.point_to_point_utf16(point)
}
pub fn version(&self) -> &clock::Global {
&self.version
}
@ -2260,6 +2264,34 @@ impl ToPoint for Point {
}
}
pub trait ToPointUtf16 {
fn to_point_utf16<'a>(&self, snapshot: &BufferSnapshot) -> PointUtf16;
}
impl ToPointUtf16 for Anchor {
fn to_point_utf16<'a>(&self, snapshot: &BufferSnapshot) -> PointUtf16 {
snapshot.summary_for_anchor(self)
}
}
impl ToPointUtf16 for usize {
fn to_point_utf16<'a>(&self, snapshot: &BufferSnapshot) -> PointUtf16 {
snapshot.offset_to_point_utf16(*self)
}
}
impl ToPointUtf16 for PointUtf16 {
fn to_point_utf16<'a>(&self, _: &BufferSnapshot) -> PointUtf16 {
*self
}
}
impl ToPointUtf16 for Point {
fn to_point_utf16<'a>(&self, snapshot: &BufferSnapshot) -> PointUtf16 {
snapshot.point_to_point_utf16(*self)
}
}
pub trait Clip {
fn clip(&self, bias: Bias, snapshot: &BufferSnapshot) -> Self;
}