Vim mode: make motion::EndOfLine works with times. (#8591)

Release Notes:

- Fixed `$` in Vim mode not taking a numeric argument (i.e. `2$` or
`4$`) ([#8007](https://github.com/zed-industries/zed/issues/8007)).

---------

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
This commit is contained in:
Wind 2024-03-01 21:00:31 +08:00 committed by GitHub
parent aeed9d0d8b
commit 9723ca95e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 7 deletions

View file

@ -301,7 +301,7 @@ fn insert_line_above(_: &mut Workspace, _: &InsertLineAbove, cx: &mut ViewContex
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.move_cursors_with(|map, cursor, _| {
let previous_line = motion::start_of_relative_buffer_row(map, cursor, -1);
let insert_point = motion::end_of_line(map, false, previous_line);
let insert_point = motion::end_of_line(map, false, previous_line, 1);
(insert_point, SelectionGoal::None)
});
});
@ -326,7 +326,8 @@ fn insert_line_below(_: &mut Workspace, _: &InsertLineBelow, cx: &mut ViewContex
let edits = selection_end_rows.into_iter().map(|row| {
let (indent, _) = map.line_indent(row);
let end_of_line =
motion::end_of_line(&map, false, DisplayPoint::new(row, 0)).to_point(&map);
motion::end_of_line(&map, false, DisplayPoint::new(row, 0), 1)
.to_point(&map);
let mut new_text = "\n".to_string();
new_text.push_str(&" ".repeat(indent as usize));
@ -1026,4 +1027,22 @@ mod test {
.await;
cx.assert_all("let result = curried_funˇ(ˇ)ˇ(ˇ)ˇ;").await;
}
#[gpui::test]
async fn test_end_of_line_with_neovim(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
// goes to current line end
cx.set_shared_state(indoc! {"ˇaa\nbb\ncc"}).await;
cx.simulate_shared_keystrokes(["$"]).await;
cx.assert_shared_state(indoc! {"aˇa\nbb\ncc"}).await;
// goes to next line end
cx.simulate_shared_keystrokes(["2", "$"]).await;
cx.assert_shared_state("aa\nbˇb\ncc").await;
// try to exceed the final line.
cx.simulate_shared_keystrokes(["4", "$"]).await;
cx.assert_shared_state("aa\nbb\ncˇc").await;
}
}