on master help sign in
Merge pull request #77 from notoria/match_brackets
74e4ac8Blaž Hrastnik
helix-core/src/match_brackets.rs+12−6
@@ -1,6 +1,6 @@
1use crate::{Range, Rope, Selection, Syntax};
1use crate::{Range, Rope, Selection, Syntax};
2
2
3−// const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')];
3+const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']'), ('<', '>')];
4// limit matching pairs to only ( ) { } [ ] < >
4// limit matching pairs to only ( ) { } [ ] < >
5
5
6#[must_use]
6#[must_use]
@@ -20,15 +20,21 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
20 None => return None,
20 None => return None,
21 };
21 };
22
22
23+ if node.is_error() {
24+ return None;
25+ }
26+
23 let start_byte = node.start_byte();
27 let start_byte = node.start_byte();
24 let end_byte = node.end_byte() - 1; // it's end exclusive
28 let end_byte = node.end_byte() - 1; // it's end exclusive
25
29
30+ if PAIRS.contains(&(doc.char(start_byte), doc.char(end_byte))) {
26− if start_byte == byte_pos {
31+ if start_byte == byte_pos {
27− return Some(doc.byte_to_char(end_byte));
32+ return Some(doc.byte_to_char(end_byte));
28− }
33+ }
29
34
30− if end_byte == byte_pos {
35+ if end_byte == byte_pos {
31− return Some(doc.byte_to_char(start_byte));
36+ return Some(doc.byte_to_char(start_byte));
37+ }
32 }
38 }
33
39
34 None
40 None