aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornotoria2021-06-05 04:00:43 +0000
committerGitHub2021-06-05 04:00:43 +0000
commit2bb71a829ef61e3e64c27db93d5260be2112fc61 (patch)
tree12a286fbe79db4d7c8ed7a382f90a6a6a8b2503f
parentc17dcb8633550a4efde56ca5b4e2b00fbf9f45e1 (diff)
Don't panic on empty file/buffer (#108)
-rw-r--r--helix-core/src/match_brackets.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs
index 38783c19..288b4586 100644
--- a/helix-core/src/match_brackets.rs
+++ b/helix-core/src/match_brackets.rs
@@ -25,6 +25,10 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
}
let start_byte = node.start_byte();
+ let len = doc.len_bytes();
+ if start_byte >= len {
+ return None;
+ }
let end_byte = node.end_byte() - 1; // it's end exclusive
let start_char = doc.byte_to_char(start_byte);
let end_char = doc.byte_to_char(end_byte);