aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Vinyals2023-07-13 13:01:44 +0000
committerGitHub2023-07-13 13:01:44 +0000
commit843ae971209d41b88b66d282979ed76303ec5e34 (patch)
treedfdbfac44becff69d17ab2facd031e9498da75e8
parent9551e4e11136542869a872a1a104b88e7308a3f0 (diff)
enhanced `surround_replace` to provide visual feedback (#7588)
-rw-r--r--helix-term/src/commands.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 42ce5777..58c17296 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -5174,11 +5174,18 @@ fn surround_replace(cx: &mut Context) {
}
};
+ let selection = selection.clone();
+ let ranges: SmallVec<[Range; 1]> = change_pos.iter().map(|&p| Range::point(p)).collect();
+ doc.set_selection(
+ view.id,
+ Selection::new(ranges, selection.primary_index() * 2),
+ );
+
cx.on_next_key(move |cx, event| {
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(
@@ -5189,6 +5196,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);
});