@@ -346,6 +346,7 @@ impl MappableCommand {
346 unindent, "Unindent selection",
346 unindent, "Unindent selection",
347 format_selections, "Format selection",
347 format_selections, "Format selection",
348 join_selections, "Join lines inside selection",
348 join_selections, "Join lines inside selection",
349+ join_selections_space, "Join lines inside selection and select spaces",
349 keep_selections, "Keep selections matching regex",
350 keep_selections, "Keep selections matching regex",
350 remove_selections, "Remove selections matching regex",
351 remove_selections, "Remove selections matching regex",
351 align_selections, "Align selections in column",
352 align_selections, "Align selections in column",
@@ -3731,7 +3732,7 @@ fn format_selections(cx: &mut Context) {
3734−fn join_selections(cx: &mut Context) {
3735+fn join_selections_inner(cx: &mut Context, select_space: bool) {
3735 use movement::skip_while;
3736 use movement::skip_while;
3736 let (view, doc) = current!(cx.editor);
3737 let (view, doc) = current!(cx.editor);
3737 let text = doc.text();
3738 let text = doc.text();
@@ -3766,9 +3767,21 @@ fn join_selections(cx: &mut Context) {
3766 // TODO: joining multiple empty lines should be replaced by a single space.
3767 // TODO: joining multiple empty lines should be replaced by a single space.
3767 // need to merge change ranges that touch
3768 // need to merge change ranges that touch
3769− let transaction = Transaction::change(doc.text(), changes.into_iter());
3770− // TODO: select inserted spaces
3770+ // select inserted spaces
3771+ let transaction = if select_space {
3772+ let ranges: SmallVec<_> = changes
3774+ .scan(0, |offset, change| {
3775+ let range = Range::point(change.0 - *offset);
3776+ *offset += change.1 - change.0 - 1; // -1 because cursor is 0-sized
3780+ let selection = Selection::new(ranges, 0);
3771− // .with_selection(selection);
3781+ Transaction::change(doc.text(), changes.into_iter()).with_selection(selection)
3783+ Transaction::change(doc.text(), changes.into_iter())
3773 doc.apply(&transaction, view.id);
3786 doc.apply(&transaction, view.id);
@@ -3797,6 +3810,14 @@ fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
3813+fn join_selections(cx: &mut Context) {
3814+ join_selections_inner(cx, false)
3817+fn join_selections_space(cx: &mut Context) {
3818+ join_selections_inner(cx, true)
3800fn keep_selections(cx: &mut Context) {
3821fn keep_selections(cx: &mut Context) {
3801 keep_or_remove_selections_impl(cx, false)
3822 keep_or_remove_selections_impl(cx, false)