diff options
author | Blaž Hrastnik | 2021-06-03 13:13:48 +0000 |
---|---|---|
committer | GitHub | 2021-06-03 13:13:48 +0000 |
commit | 74e4ac8d499360bcf381527c8d8c84c6837ce1cb (patch) | |
tree | d86fbece4a7bb3a5b695670e3cae15e957d3d1ad /helix-core/src/match_brackets.rs | |
parent | 661dbdca57f76cbd22f3e62f8b87ee2146a50bab (diff) | |
parent | 4fe654cf9a4910f67da6696773f3edc41f25755d (diff) |
Merge pull request #77 from notoria/match_brackets
Fix match_brackets::find
Diffstat (limited to 'helix-core/src/match_brackets.rs')
-rw-r--r-- | helix-core/src/match_brackets.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs index fd161776..2d2eb4a9 100644 --- a/helix-core/src/match_brackets.rs +++ b/helix-core/src/match_brackets.rs @@ -1,6 +1,6 @@ use crate::{Range, Rope, Selection, Syntax}; -// const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')]; +const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']'), ('<', '>')]; // limit matching pairs to only ( ) { } [ ] < > #[must_use] @@ -20,15 +20,21 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> { None => return None, }; + if node.is_error() { + return None; + } + let start_byte = node.start_byte(); let end_byte = node.end_byte() - 1; // it's end exclusive - if start_byte == byte_pos { - return Some(doc.byte_to_char(end_byte)); - } + if PAIRS.contains(&(doc.char(start_byte), doc.char(end_byte))) { + if start_byte == byte_pos { + return Some(doc.byte_to_char(end_byte)); + } - if end_byte == byte_pos { - return Some(doc.byte_to_char(start_byte)); + if end_byte == byte_pos { + return Some(doc.byte_to_char(start_byte)); + } } None |