diff options
author | Alex Vinyals | 2023-06-05 14:13:00 +0000 |
---|---|---|
committer | GitHub | 2023-06-05 14:13:00 +0000 |
commit | a2b8cfdb8c8c97ba01bc7913cab15df94705f462 (patch) | |
tree | 95c57031918a8f730d7e8dd0f361afd24770e65f /helix-term | |
parent | 428d33ab504cea9b66404356c6fe12fbbdc4db7d (diff) |
feat(core): add plaintext matching fallback to tree-sitter matching (#4288)
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 911c9c1f..1e89fe1c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4528,20 +4528,23 @@ fn select_prev_sibling(cx: &mut Context) { fn match_brackets(cx: &mut Context) { let (view, doc) = current!(cx.editor); + let is_select = cx.editor.mode == Mode::Select; + let text = doc.text(); + let text_slice = text.slice(..); - if let Some(syntax) = doc.syntax() { - let text = doc.text().slice(..); - let selection = doc.selection(view.id).clone().transform(|range| { - if let Some(pos) = - match_brackets::find_matching_bracket_fuzzy(syntax, doc.text(), range.cursor(text)) - { - range.put_cursor(text, pos, cx.editor.mode == Mode::Select) - } else { - range - } - }); - doc.set_selection(view.id, selection); - } + let selection = doc.selection(view.id).clone().transform(|range| { + let pos = range.cursor(text_slice); + if let Some(matched_pos) = doc.syntax().map_or_else( + || match_brackets::find_matching_bracket_current_line_plaintext(text, pos), + |syntax| match_brackets::find_matching_bracket_fuzzy(syntax, text, pos), + ) { + range.put_cursor(text_slice, matched_pos, is_select) + } else { + range + } + }); + + doc.set_selection(view.id, selection); } // |