Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

rope: Assert utf8 boundary of start of `Chunks::new` range (#40253)

Lukas Wirthec0eeaf69df7
diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rs
index c349f3f4513..db79e6b03f5 100644
--- a/crates/rope/src/rope.rs
+++ b/crates/rope/src/rope.rs
@@ -673,6 +673,12 @@ impl<'a> Chunks<'a> {
chunks.seek(&range.start, Bias::Right);
range.start
};
+ let chunk_offset = offset - chunks.start();
+ if let Some(chunk) = chunks.item()
+ && !chunk.text.is_char_boundary(chunk_offset)
+ {
+ panic!("byte index {} is not a char boundary", offset);
+ }
Self {
chunks,
range,