Merge pull request #77 from notoria/match_brackets

Fix match_brackets::find
pull/95/head
Blaž Hrastnik 4 years ago committed by GitHub
commit 74e4ac8d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
use crate::{Range, Rope, Selection, Syntax}; use crate::{Range, Rope, Selection, Syntax};
// const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')]; const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']'), ('<', '>')];
// limit matching pairs to only ( ) { } [ ] < > // limit matching pairs to only ( ) { } [ ] < >
#[must_use] #[must_use]
@ -20,9 +20,14 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
None => return None, None => return None,
}; };
if node.is_error() {
return None;
}
let start_byte = node.start_byte(); let start_byte = node.start_byte();
let end_byte = node.end_byte() - 1; // it's end exclusive let end_byte = node.end_byte() - 1; // it's end exclusive
if PAIRS.contains(&(doc.char(start_byte), doc.char(end_byte))) {
if start_byte == byte_pos { if start_byte == byte_pos {
return Some(doc.byte_to_char(end_byte)); return Some(doc.byte_to_char(end_byte));
} }
@ -30,6 +35,7 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
if end_byte == byte_pos { if end_byte == byte_pos {
return Some(doc.byte_to_char(start_byte)); return Some(doc.byte_to_char(start_byte));
} }
}
None None
} }

Loading…
Cancel
Save