Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhanced surround_replace to provide visual feedback #7588

Merged
merged 7 commits into from
Jul 13, 2023
17 changes: 16 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5115,11 +5115,25 @@ 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 {
alevinval marked this conversation as resolved.
Show resolved Hide resolved
let from = *p.first().unwrap();
let to = *p.get(1).unwrap();
alevinval marked this conversation as resolved.
Show resolved Hide resolved
ranges.push(Range::new(from, from + 1));
ranges.push(Range::new(to, to + 1));
}
});
let feedback = Selection::new(ranges, 0);
doc.set_selection(view.id, feedback);

cx.on_next_key(move |cx, event| {
archseer marked this conversation as resolved.
Show resolved Hide resolved
let (view, doc) = current!(cx.editor);
let to = match event.char() {
Some(to) => to,
None => return,
None => return doc.set_selection(view.id, selection),
};
let (open, close) = surround::get_pair(to);
let transaction = Transaction::change(
Expand All @@ -5130,6 +5144,7 @@ fn surround_replace(cx: &mut Context) {
(pos, pos + 1, Some(t))
}),
);
doc.set_selection(view.id, selection);
doc.apply(&transaction, view.id);
exit_select_mode(cx);
});
Expand Down