-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Subword motion ignores line breaks, jumps to next line unexpectedly #17780
Comments
I see the same issue on macOS, so not Linux specific. |
This is normal behavior, because it uses multiple lines to search, which simulates the movement of a word. fn next_subword_start(
map: &DisplaySnapshot,
mut point: DisplayPoint,
ignore_punctuation: bool,
times: usize,
) -> DisplayPoint {
let classifier = map
.buffer_snapshot
.char_classifier_at(point.to_point(map))
.ignore_punctuation(ignore_punctuation);
for _ in 0..times {
let mut crossed_newline = false;
let new_point = movement::find_boundary(map, point, FindRange::MultiLine, |left, right| {
let left_kind = classifier.kind(left);
let right_kind = classifier.kind(right);
let at_newline = right == '\n';
let is_word_start = (left_kind != right_kind) && !left.is_alphanumeric();
let is_subword_start =
left == '_' && right != '_' || left.is_lowercase() && right.is_uppercase();
let found = (!right.is_whitespace() && (is_word_start || is_subword_start))
|| at_newline && crossed_newline
|| at_newline && left == '\n'; // Prevents skipping repeated empty lines
crossed_newline |= at_newline;
found
});
if point == new_point {
break;
}
point = new_point;
}
point
} |
hmm it makes subword motions pretty much unusable for me and is inconsistent with non-subword motions. I have a hard time seeing how this could be expected behaviour? In this screencast I type Screen.Recording.2025-01-06.at.11.08.15.mov |
Oh, sorry I misunderstood, indeed there is a problem. When using e, it will unexpectedly skip many words and may even skip many lines. The key code is here pub(crate) fn next_subword_end(
map: &DisplaySnapshot,
mut point: DisplayPoint,
ignore_punctuation: bool,
times: usize,
allow_cross_newline: bool,
) -> DisplayPoint {
let classifier = map
.buffer_snapshot
.char_classifier_at(point.to_point(map))
.ignore_punctuation(ignore_punctuation);
for _ in 0..times {
let new_point = next_char(map, point, allow_cross_newline);
let mut crossed_newline = false;
let mut need_backtrack = false;
let new_point =
movement::find_boundary(map, new_point, FindRange::MultiLine, |left, right| {
let left_kind = classifier.kind(left);
let right_kind = classifier.kind(right);
let at_newline = right == '\n';
if !allow_cross_newline && at_newline {
return true;
}
let is_word_end = (left_kind != right_kind) && !right.is_alphanumeric();
let is_subword_end =
left != '_' && right == '_' || left.is_lowercase() && right.is_uppercase();
let found = !left.is_whitespace() && !at_newline && (is_word_end || is_subword_end);
if found && (is_word_end || is_subword_end) {
need_backtrack = true;
}
crossed_newline |= at_newline;
found
});
let mut new_point = map.clip_point(new_point, Bias::Left);
if need_backtrack {
*new_point.column_mut() -= 1;
}
if point == new_point {
break;
}
point = new_point;
}
point
} If you replace I don't quite understand the function of the |
Check for existing issues
Describe the bug / provide steps to reproduce it
Description
The Subword motion feature is not working as expected when it encounters end-of-line characters. Instead of treating the end of the line as a boundary, it immediately jumps to the subword end of the next word on the line below.
Steps to Reproduce
Expected Behavior
The cursor should move to the end of the current word and stop at the end of the line.
Actual Behavior
The cursor skips the end-of-line character(s) and jumps to the subword end of the first word on the next line.
Environment
Zed: v0.152.3 (Zed)
OS: Linux Wayland nixos 24.11
Memory: 30.6 GiB
Architecture: x86_64
GPU: AMD Radeon Graphics (RADV REMBRANDT) || radv || Mesa 24.2.2
If applicable, add mockups / screenshots to help explain present your vision of the feature
2024-09-13-091340_wf.mp4
If applicable, attach your Zed.log file to this issue.
Zed.log
The text was updated successfully, but these errors were encountered: