Skip to content

Commit

Permalink
feedback: add plain-text fallback only when there is no syntax (tree-…
Browse files Browse the repository at this point in the history
…sitter)
  • Loading branch information
alevinval committed Jun 1, 2023
1 parent 715b928 commit adf0fbd
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4528,23 +4528,24 @@ 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();
let text_slice = text.slice(..);
let is_select = cx.editor.mode == Mode::Select;
let selection = doc.selection(view.id).clone().transform(|range| {
let pos = range.cursor(text_slice);
if let Some(pos) = match_brackets::find_matching_bracket_fuzzy(syntax, text, pos)
.or_else(|| match_brackets::find_matching_bracket_current_line_plaintext(text, pos))
{
range.put_cursor(text_slice, pos, is_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()
.and_then(|syntax| match_brackets::find_matching_bracket_fuzzy(syntax, text, pos))
.or_else(|| match_brackets::find_matching_bracket_current_line_plaintext(text, pos))
{
range.put_cursor(text_slice, matched_pos, is_select)
} else {
range
}
});

doc.set_selection(view.id, selection);
}

//
Expand Down

0 comments on commit adf0fbd

Please sign in to comment.