From 2bb71a829ef61e3e64c27db93d5260be2112fc61 Mon Sep 17 00:00:00 2001 From: notoria Date: Sat, 5 Jun 2021 06:00:43 +0200 Subject: [PATCH] Don't panic on empty file/buffer (#108) --- helix-core/src/match_brackets.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs index 38783c19e..288b45861 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 { } 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);