Clamp for all UTF-16 to offset conversions which used to use ToOffset
This commit is contained in:
parent
f9cbed5a1f
commit
bb32599ded
4 changed files with 43 additions and 39 deletions
|
@ -1808,12 +1808,23 @@ impl BufferSnapshot {
|
|||
self.anchor_at(position, Bias::Left)
|
||||
}
|
||||
|
||||
pub fn clamped_anchor_before<T: ToOffsetClamped>(&self, position: T) -> Anchor {
|
||||
self.anchor_at_offset(position.to_offset_clamped(self), Bias::Left)
|
||||
}
|
||||
|
||||
pub fn anchor_after<T: ToOffset>(&self, position: T) -> Anchor {
|
||||
self.anchor_at(position, Bias::Right)
|
||||
}
|
||||
|
||||
pub fn clamped_anchor_after<T: ToOffsetClamped>(&self, position: T) -> Anchor {
|
||||
self.anchor_at_offset(position.to_offset_clamped(self), Bias::Right)
|
||||
}
|
||||
|
||||
pub fn anchor_at<T: ToOffset>(&self, position: T, bias: Bias) -> Anchor {
|
||||
let offset = position.to_offset(self);
|
||||
self.anchor_at_offset(position.to_offset(self), bias)
|
||||
}
|
||||
|
||||
fn anchor_at_offset(&self, offset: usize, bias: Bias) -> Anchor {
|
||||
if bias == Bias::Left && offset == 0 {
|
||||
Anchor::MIN
|
||||
} else if bias == Bias::Right && offset == self.len() {
|
||||
|
@ -2369,12 +2380,6 @@ impl ToOffset for Point {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToOffset for PointUtf16 {
|
||||
fn to_offset<'a>(&self, snapshot: &BufferSnapshot) -> usize {
|
||||
snapshot.point_utf16_to_offset(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToOffset for usize {
|
||||
fn to_offset<'a>(&self, snapshot: &BufferSnapshot) -> usize {
|
||||
assert!(*self <= snapshot.len(), "offset {self} is out of range");
|
||||
|
@ -2382,12 +2387,6 @@ impl ToOffset for usize {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToOffset for OffsetUtf16 {
|
||||
fn to_offset<'a>(&self, snapshot: &BufferSnapshot) -> usize {
|
||||
snapshot.offset_utf16_to_offset(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToOffset for Anchor {
|
||||
fn to_offset<'a>(&self, snapshot: &BufferSnapshot) -> usize {
|
||||
snapshot.summary_for_anchor(self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue