Add support for visual ranges ending with a newline

These primarily happen when first entering visual mode, but can also
be created with objects like `vi{`.

Along the way fix the way ranges like `vi{` are selected to be more
similar to nvim.
This commit is contained in:
Conrad Irwin 2023-07-27 21:39:37 -06:00
parent b53fb8633e
commit 5edcb74760
21 changed files with 301 additions and 135 deletions

View file

@ -2,7 +2,7 @@ use std::sync::Arc;
use editor::{
char_kind,
display_map::{Clip, DisplaySnapshot, ToDisplayPoint},
display_map::{DisplaySnapshot, ToDisplayPoint},
movement, Bias, CharKind, DisplayPoint, ToOffset,
};
use gpui::{actions, impl_actions, AppContext, WindowContext};
@ -295,11 +295,7 @@ impl Motion {
SelectionGoal::None,
),
EndOfParagraph => (
map.clip_point_with(
movement::end_of_paragraph(map, point, times),
Bias::Left,
Clip::EndOfLine,
),
map.clip_at_line_end(movement::end_of_paragraph(map, point, times)),
SelectionGoal::None,
),
CurrentLine => (end_of_line(map, point), SelectionGoal::None),
@ -387,7 +383,7 @@ impl Motion {
fn left(map: &DisplaySnapshot, mut point: DisplayPoint, times: usize) -> DisplayPoint {
for _ in 0..times {
point = map.move_left(point, Clip::None);
point = movement::saturating_left(map, point);
if point.column() == 0 {
break;
}
@ -428,7 +424,7 @@ fn up(
pub(crate) fn right(map: &DisplaySnapshot, mut point: DisplayPoint, times: usize) -> DisplayPoint {
for _ in 0..times {
let new_point = map.clip_point(map.move_right(point, Clip::None), Bias::Right);
let new_point = movement::saturating_right(map, point);
if point == new_point {
break;
}