aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--helix-core/src/match_brackets.rs18
-rw-r--r--helix-term/src/ui/editor.rs14
2 files changed, 26 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
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index bd7846a4..15e64b72 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -306,6 +306,20 @@ impl EditorView {
),
cursor_style,
);
+ if let Some(syntax) = doc.syntax() {
+ use helix_core::match_brackets;
+ let pos = doc.selection(view.id).cursor();
+ let pos = match_brackets::find(syntax, doc.text(), pos);
+ if let Some(pos) = pos {
+ let pos = view.screen_coords_at_pos(doc, text, pos);
+ if let Some(pos) = pos {
+ let style = Style::default().add_modifier(Modifier::REVERSED);
+ surface
+ .get_mut(pos.col as u16 + OFFSET, pos.row as u16)
+ .set_style(style);
+ }
+ }
+ }
}
}
}