Skip to content

Commit

Permalink
enhanced surround_replace to provide visual feedback (helix-editor#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alevinval authored and Schuyler Mortimer committed Jul 10, 2024
1 parent ef59e95 commit 1b26282
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5178,11 +5178,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(
Expand All @@ -5193,6 +5200,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

0 comments on commit 1b26282

Please sign in to comment.