From 7c9e4e513c813a09bce5abdea0632da7374cf2bb Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 29 Dec 2021 23:11:54 -0800 Subject: [PATCH] Provide an accurate panic message when translating points off the end of a line Maybe we should fail more gracefully in this case, but I think we should at least make the message accurate and see how we do. --- crates/text/src/rope.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/text/src/rope.rs b/crates/text/src/rope.rs index 70399e15f544e4ecc77fef0efb19da2d84976071..89ce278de1a65a2f53658b188cf6452c7d973960 100644 --- a/crates/text/src/rope.rs +++ b/crates/text/src/rope.rs @@ -565,6 +565,12 @@ impl Chunk { if ch == '\n' { point.row += 1; + if point.row > target.row { + panic!( + "point {:?} is beyond the end of a line with length {}", + target, point.column + ); + } point.column = 0; } else { point.column += ch.len_utf8() as u32;