Skip to content

Commit

Permalink
feedback: much cleaner for_each logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alevinval committed Jul 10, 2023
1 parent f26677d commit 6705e0f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 stabilized
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);
Expand Down

0 comments on commit 6705e0f

Please sign in to comment.