Skip to content

Word movement select from first range #1570

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

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
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 @@ -1042,11 +1048,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 @@ -1298,11 +1304,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 @@ -1383,11 +1389,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 @@ -1566,11 +1572,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 @@ -1650,11 +1656,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 @@ -1732,11 +1738,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 @@ -1900,11 +1906,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 @@ -1994,11 +2000,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