diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index e446d8cc4..9b4dbe423 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -251,14 +251,20 @@ fn word_move(slice: RopeSlice, range: Range, count: usize, target: WordMotionTar // Do the main work. let mut range = start_range; + let mut first_range = None; for _ in 0..count { let next_range = slice.chars_at(range.head).range_to_target(target, range); if range == next_range { break; } range = next_range; + if first_range.is_none() { + first_range = Some(range); + } } - range + let first_range = first_range.unwrap_or(range); + let last_range = range; + Range::new(first_range.anchor, last_range.head) } pub fn move_prev_paragraph( @@ -1040,11 +1046,11 @@ mod test { ]), ("Multiple motions at once resolve correctly", vec![ - (3, Range::new(0, 0), Range::new(17, 20)), + (3, Range::new(0, 0), Range::new(0, 20)), ]), ("Excessive motions are performed partially", vec![ - (999, Range::new(0, 0), Range::new(32, 41)), + (999, Range::new(0, 0), Range::new(0, 41)), ]), ("", // Edge case of moving forward in empty string vec![ @@ -1296,11 +1302,11 @@ mod test { ]), ("Multiple motions at once resolve correctly", vec![ - (3, Range::new(0, 0), Range::new(17, 20)), + (3, Range::new(0, 0), Range::new(0, 20)), ]), ("Excessive motions are performed partially", vec![ - (999, Range::new(0, 0), Range::new(32, 41)), + (999, Range::new(0, 0), Range::new(0, 41)), ]), ("", // Edge case of moving forward in empty string vec![ @@ -1381,11 +1387,11 @@ mod test { ]), ("Multiple motions at once resolve correctly", vec![ - (3, Range::new(18, 18), Range::new(9, 0)), + (3, Range::new(18, 18), Range::new(19, 0)), ]), ("Excessive motions are performed partially", vec![ - (999, Range::new(40, 40), Range::new(10, 0)), + (999, Range::new(40, 40), Range::new(41, 0)), ]), ("", // Edge case of moving backwards in empty string vec![ @@ -1564,11 +1570,11 @@ mod test { ), ( "Multiple motions at once resolve correctly", - vec![(3, Range::new(19, 19), Range::new(9, 0))], + vec![(3, Range::new(0, 19), Range::new(19, 0))], ), ( "Excessive motions are performed partially", - vec![(999, Range::new(40, 40), Range::new(10, 0))], + vec![(999, Range::new(40, 40), Range::new(41, 0))], ), ( "", // Edge case of moving backwards in empty string @@ -1648,11 +1654,11 @@ mod test { ]), ("Multiple motions at once resolve correctly", vec![ - (3, Range::new(0, 0), Range::new(16, 19)), + (3, Range::new(0, 0), Range::new(0, 19)), ]), ("Excessive motions are performed partially", vec![ - (999, Range::new(0, 0), Range::new(31, 41)), + (999, Range::new(0, 0), Range::new(0, 41)), ]), ("", // Edge case of moving forward in empty string vec![ @@ -1730,11 +1736,11 @@ mod test { ]), ("Multiple motions at once resolve correctly", vec![ - (3, Range::new(24, 24), Range::new(16, 8)), + (3, Range::new(24, 24), Range::new(24, 8)), ]), ("Excessive motions are performed partially", vec![ - (999, Range::new(40, 40), Range::new(9, 0)), + (999, Range::new(40, 40), Range::new(41, 0)), ]), ("", // Edge case of moving backwards in empty string vec![ @@ -1898,11 +1904,11 @@ mod test { ]), ("Multiple motions at once resolve correctly", vec![ - (3, Range::new(0, 0), Range::new(16, 19)), + (3, Range::new(0, 0), Range::new(0, 19)), ]), ("Excessive motions are performed partially", vec![ - (999, Range::new(0, 0), Range::new(31, 41)), + (999, Range::new(0, 0), Range::new(0, 41)), ]), ("", // Edge case of moving forward in empty string vec![ @@ -1992,11 +1998,11 @@ mod test { ), ( "Multiple motions at once resolve correctly", - vec![(3, Range::new(19, 19), Range::new(8, 0))], + vec![(3, Range::new(19, 19), Range::new(19, 0))], ), ( "Excessive motions are performed partially", - vec![(999, Range::new(40, 40), Range::new(9, 0))], + vec![(999, Range::new(40, 40), Range::new(41, 0))], ), ( "", // Edge case of moving backwards in empty string