vim: Fix 1G

Before this change code could not distinguish between a user providing a
count of 1 and no count at all.

Fixes: zed-industries/community#710
This commit is contained in:
Conrad Irwin 2023-06-21 22:36:48 -06:00
parent 5291bf3d9f
commit 0cacf01f90
8 changed files with 49 additions and 26 deletions

View file

@ -93,7 +93,7 @@ pub fn init(cx: &mut AppContext) {
pub fn normal_motion(
motion: Motion,
operator: Option<Operator>,
times: usize,
times: Option<usize>,
cx: &mut WindowContext,
) {
Vim::update(cx, |vim, cx| {
@ -129,7 +129,7 @@ pub fn normal_object(object: Object, cx: &mut WindowContext) {
})
}
fn move_cursor(vim: &mut Vim, motion: Motion, times: usize, cx: &mut WindowContext) {
fn move_cursor(vim: &mut Vim, motion: Motion, times: Option<usize>, cx: &mut WindowContext) {
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.move_cursors_with(|map, cursor, goal| {
@ -147,7 +147,7 @@ fn insert_after(_: &mut Workspace, _: &InsertAfter, cx: &mut ViewContext<Workspa
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.maybe_move_cursors_with(|map, cursor, goal| {
Motion::Right.move_point(map, cursor, goal, 1)
Motion::Right.move_point(map, cursor, goal, None)
});
});
});
@ -164,7 +164,7 @@ fn insert_first_non_whitespace(
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.maybe_move_cursors_with(|map, cursor, goal| {
Motion::FirstNonWhitespace.move_point(map, cursor, goal, 1)
Motion::FirstNonWhitespace.move_point(map, cursor, goal, None)
});
});
});
@ -177,7 +177,7 @@ fn insert_end_of_line(_: &mut Workspace, _: &InsertEndOfLine, cx: &mut ViewConte
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.maybe_move_cursors_with(|map, cursor, goal| {
Motion::EndOfLine.move_point(map, cursor, goal, 1)
Motion::EndOfLine.move_point(map, cursor, goal, None)
});
});
});
@ -237,7 +237,7 @@ fn insert_line_below(_: &mut Workspace, _: &InsertLineBelow, cx: &mut ViewContex
});
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.maybe_move_cursors_with(|map, cursor, goal| {
Motion::EndOfLine.move_point(map, cursor, goal, 1)
Motion::EndOfLine.move_point(map, cursor, goal, None)
});
});
editor.edit_with_autoindent(edits, cx);