Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word movement select from first range #1570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
pickfire committed Oct 1, 2024
commit cb85ed4772432851b8202ed4456834f539f45b4c
40 changes: 23 additions & 17 deletions helix-core/src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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
Expand Down