From a93638390a65233a55c94fa1e20344472660f6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Vinyals=20Valdepe=C3=B1as?= Date: Mon, 10 Jul 2023 11:22:44 +0200 Subject: [PATCH] feedback: much cleaner `for_each` logic --- helix-term/src/commands.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f3c94304c5b1f..34ea09902e934 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5118,16 +5118,13 @@ fn surround_replace(cx: &mut Context) { // Visual feedback let selection = selection.clone(); let mut ranges: SmallVec<[Range; 1]> = SmallVec::new(); - change_pos.chunks(2).for_each(|p| { - if p.len() == 2 { - let from = *p.first().unwrap(); - let to = *p.get(1).unwrap(); - ranges.push(Range::new(from, from + 1)); - ranges.push(Range::new(to, to + 1)); - } + // TODO: Use [`array_chunks`] once stabilised + change_pos.chunks_exact(2).for_each(|p| { + let [from, to] = *p else { return }; + ranges.push(Range::point(from)); + ranges.push(Range::point(to)); }); - let feedback = Selection::new(ranges, 0); - doc.set_selection(view.id, feedback); + doc.set_selection(view.id, Selection::new(ranges, 0)); cx.on_next_key(move |cx, event| { let (view, doc) = current!(cx.editor);