diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c9a54d5195cd..540ca9b36618 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -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); } //