on master help sign in
Fix match_brackets::find
commit4fe654cf9a4910f67da6696773f3edc41f25755d authornotoria <notoria@users.noreply.github.com> dateThu 3 Jun 2021, 10:35 (5 years ago) parent7e86032
1 file changed+12−6
helix-core/src/match_brackets.rs+12−6
helix-core/src/match_brackets.rs+12−6
@@ -1,6 +1,6 @@
11use crate::{Range, Rope, Selection, Syntax};
22
3−// const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')];
3+const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']'), ('<', '>')];
44// limit matching pairs to only ( ) { } [ ] < >
55
66#[must_use]
@@ -20,15 +20,21 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
2020 None => return None,
2121 };
2222
23+ if node.is_error() {
24+ return None;
25+ }
26+
2327 let start_byte = node.start_byte();
2428 let end_byte = node.end_byte() - 1; // it's end exclusive
2529
26− if start_byte == byte_pos {
27− return Some(doc.byte_to_char(end_byte));
28− }
30+ if PAIRS.contains(&(doc.char(start_byte), doc.char(end_byte))) {
31+ if start_byte == byte_pos {
32+ return Some(doc.byte_to_char(end_byte));
33+ }
2934
30− if end_byte == byte_pos {
31− return Some(doc.byte_to_char(start_byte));
35+ if end_byte == byte_pos {
36+ return Some(doc.byte_to_char(start_byte));
37+ }
3238 }
3339
3440 None