text: Implement Rope::clip_offset in terms of the new utf8 boundary methods (#38630)

Release Notes:

- N/A
This commit is contained in:
Lukas Wirth
2025-09-22 11:45:23 +00:00
committed by GitHub
parent 50bd8bc255
commit 55dc9ff7ca
5 changed files with 12 additions and 26 deletions
+3 -1
View File
@@ -2128,7 +2128,7 @@ impl BufferSnapshot {
let row_end_offset = if row >= self.max_point().row {
self.len()
} else {
Point::new(row + 1, 0).to_offset(self) - 1
Point::new(row + 1, 0).to_previous_offset(self)
};
(row_end_offset - row_start_offset) as u32
}
@@ -3076,11 +3076,13 @@ impl operation_queue::Operation for Operation {
pub trait ToOffset {
fn to_offset(&self, snapshot: &BufferSnapshot) -> usize;
/// Turns this point into the next offset in the buffer that comes after this, respecting utf8 boundaries.
fn to_next_offset(&self, snapshot: &BufferSnapshot) -> usize {
snapshot
.visible_text
.ceil_char_boundary(self.to_offset(snapshot) + 1)
}
/// Turns this point into the previous offset in the buffer that comes before this, respecting utf8 boundaries.
fn to_previous_offset(&self, snapshot: &BufferSnapshot) -> usize {
snapshot
.visible_text