mirror of https://github.com/helix-editor/helix
Don't panic on empty file/buffer (#108)
parent
c17dcb8633
commit
2bb71a829e
|
@ -25,6 +25,10 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let start_byte = node.start_byte();
|
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 end_byte = node.end_byte() - 1; // it's end exclusive
|
||||||
let start_char = doc.byte_to_char(start_byte);
|
let start_char = doc.byte_to_char(start_byte);
|
||||||
let end_char = doc.byte_to_char(end_byte);
|
let end_char = doc.byte_to_char(end_byte);
|
||||||
|
|
Loading…
Reference in New Issue