multi_buffer: Assert char boundary for panic due to point_to_buffer_offset (#40777)

In an attempt to figure out what's wrong with `point_to_buffer_offset`
for crash https://github.com/zed-industries/zed/issues/40453. We want to
know which branch among these two is the bad one.

Release Notes:

- N/A

Co-authored-by: Lukas Wirth <lukas@zed.dev>
This commit is contained in:
Smit Barmase
2025-10-21 19:01:35 +05:30
committed by GitHub
co-authored by Lukas Wirth
parent cad06011c5
commit 10b9ae5e44
3 changed files with 38 additions and 11 deletions
+1 -10
View File
@@ -2402,17 +2402,8 @@ impl BufferSnapshot {
} else {
if offset > self.visible_text.len() {
panic!("offset {} is out of bounds", offset)
} else if !self.visible_text.is_char_boundary(offset) {
// find the character
let char_start = self.visible_text.floor_char_boundary(offset);
// `char_start` must be less than len and a char boundary
let ch = self.visible_text.chars_at(char_start).next().unwrap();
let char_range = char_start..char_start + ch.len_utf8();
panic!(
"byte index {} is not a char boundary; it is inside {:?} (bytes {:?})",
offset, ch, char_range,
);
}
self.visible_text.assert_char_boundary(offset);
let (start, _, item) = self.fragments.find::<usize, _>(&None, &offset, bias);
let fragment = item.unwrap();
let overshoot = offset - start;