aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index bd0a60b7..0b2ea0b8 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -4372,16 +4372,27 @@ fn join_selections_impl(cx: &mut Context, select_space: bool) {
// select inserted spaces
let transaction = if select_space {
+ let mut offset: usize = 0;
let ranges: SmallVec<_> = changes
.iter()
- .scan(0, |offset, change| {
- let range = Range::point(change.0 - *offset);
- *offset += change.1 - change.0 - 1; // -1 because cursor is 0-sized
- Some(range)
+ .filter_map(|change| {
+ if change.2.is_some() {
+ let range = Range::point(change.0 - offset);
+ offset += change.1 - change.0 - 1; // -1 adjusts for the replacement of the range by a space
+ Some(range)
+ } else {
+ offset += change.1 - change.0;
+ None
+ }
})
.collect();
- let selection = Selection::new(ranges, 0);
- Transaction::change(text, changes.into_iter()).with_selection(selection)
+ let t = Transaction::change(text, changes.into_iter());
+ if ranges.is_empty() {
+ t
+ } else {
+ let selection = Selection::new(ranges, 0);
+ t.with_selection(selection)
+ }
} else {
Transaction::change(text, changes.into_iter())
};