From bc6a34d97edae55811c2476278a6288d7d258af3 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Fri, 29 Oct 2021 09:08:53 +0800 Subject: Make match work with extend and multi cursors (#920) --- helix-term/src/commands.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'helix-term/src/commands.rs') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 9eda2c23..28657865 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4386,14 +4386,15 @@ fn match_brackets(cx: &mut Context) { let (view, doc) = current!(cx.editor); if let Some(syntax) = doc.syntax() { - let pos = doc - .selection(view.id) - .primary() - .cursor(doc.text().slice(..)); - if let Some(pos) = match_brackets::find(syntax, doc.text(), pos) { - let selection = Selection::point(pos); - doc.set_selection(view.id, selection); - }; + let text = doc.text().slice(..); + let selection = doc.selection(view.id).clone().transform(|range| { + if let Some(pos) = match_brackets::find(syntax, doc.text(), range.anchor) { + range.put_cursor(text, pos, doc.mode == Mode::Select) + } else { + range + } + }); + doc.set_selection(view.id, selection); } } -- cgit v1.2.3-70-g09d2