Word movement select from first range

3w currently selects the 3rd word, this changes the behavior to select
all 3 words rather than just the last.
pull/1570/head
Ivan Tham 2 months ago
parent 57ec3b7330
commit cb85ed4772

@ -251,14 +251,20 @@ fn word_move(slice: RopeSlice, range: Range, count: usize, target: WordMotionTar
// Do the main work. // Do the main work.
let mut range = start_range; let mut range = start_range;
let mut first_range = None;
for _ in 0..count { for _ in 0..count {
let next_range = slice.chars_at(range.head).range_to_target(target, range); let next_range = slice.chars_at(range.head).range_to_target(target, range);
if range == next_range { if range == next_range {
break; break;
} }
range = next_range; 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( pub fn move_prev_paragraph(
@ -1040,11 +1046,11 @@ mod test {
]), ]),
("Multiple motions at once resolve correctly", ("Multiple motions at once resolve correctly",
vec![ vec![
(3, Range::new(0, 0), Range::new(17, 20)), (3, Range::new(0, 0), Range::new(0, 20)),
]), ]),
("Excessive motions are performed partially", ("Excessive motions are performed partially",
vec![ 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 ("", // Edge case of moving forward in empty string
vec![ vec![
@ -1296,11 +1302,11 @@ mod test {
]), ]),
("Multiple motions at once resolve correctly", ("Multiple motions at once resolve correctly",
vec![ vec![
(3, Range::new(0, 0), Range::new(17, 20)), (3, Range::new(0, 0), Range::new(0, 20)),
]), ]),
("Excessive motions are performed partially", ("Excessive motions are performed partially",
vec![ 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 ("", // Edge case of moving forward in empty string
vec![ vec![
@ -1381,11 +1387,11 @@ mod test {
]), ]),
("Multiple motions at once resolve correctly", ("Multiple motions at once resolve correctly",
vec![ vec![
(3, Range::new(18, 18), Range::new(9, 0)), (3, Range::new(18, 18), Range::new(19, 0)),
]), ]),
("Excessive motions are performed partially", ("Excessive motions are performed partially",
vec![ 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 ("", // Edge case of moving backwards in empty string
vec![ vec![
@ -1564,11 +1570,11 @@ mod test {
), ),
( (
"Multiple motions at once resolve correctly", "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", "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 "", // Edge case of moving backwards in empty string
@ -1648,11 +1654,11 @@ mod test {
]), ]),
("Multiple motions at once resolve correctly", ("Multiple motions at once resolve correctly",
vec![ vec![
(3, Range::new(0, 0), Range::new(16, 19)), (3, Range::new(0, 0), Range::new(0, 19)),
]), ]),
("Excessive motions are performed partially", ("Excessive motions are performed partially",
vec![ 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 ("", // Edge case of moving forward in empty string
vec![ vec![
@ -1730,11 +1736,11 @@ mod test {
]), ]),
("Multiple motions at once resolve correctly", ("Multiple motions at once resolve correctly",
vec![ vec![
(3, Range::new(24, 24), Range::new(16, 8)), (3, Range::new(24, 24), Range::new(24, 8)),
]), ]),
("Excessive motions are performed partially", ("Excessive motions are performed partially",
vec![ 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 ("", // Edge case of moving backwards in empty string
vec![ vec![
@ -1898,11 +1904,11 @@ mod test {
]), ]),
("Multiple motions at once resolve correctly", ("Multiple motions at once resolve correctly",
vec![ vec![
(3, Range::new(0, 0), Range::new(16, 19)), (3, Range::new(0, 0), Range::new(0, 19)),
]), ]),
("Excessive motions are performed partially", ("Excessive motions are performed partially",
vec![ 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 ("", // Edge case of moving forward in empty string
vec![ vec![
@ -1992,11 +1998,11 @@ mod test {
), ),
( (
"Multiple motions at once resolve correctly", "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", "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 "", // Edge case of moving backwards in empty string

Loading…
Cancel
Save