From 93461d366c863ae7f7bf3a83eb14890d51d4bd93 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 18 Aug 2023 12:24:39 -0600 Subject: [PATCH] Fix to go to non-whitespace character Fixes: zed-industries/community#831 --- crates/vim/src/motion.rs | 13 ++++++++++++- crates/vim/test_data/test_next_line_start.json | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 crates/vim/test_data/test_next_line_start.json diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index 29a1ba7df8..13c22afdaa 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -651,7 +651,10 @@ fn find_backward( fn next_line_start(map: &DisplaySnapshot, point: DisplayPoint, times: usize) -> DisplayPoint { let new_row = (point.row() + times as u32).min(map.max_buffer_row()); - map.clip_point(DisplayPoint::new(new_row, 0), Bias::Left) + first_non_whitespace( + map, + map.clip_point(DisplayPoint::new(new_row, 0), Bias::Left), + ) } #[cfg(test)] @@ -799,4 +802,12 @@ mod test { cx.simulate_shared_keystrokes([","]).await; cx.assert_shared_state("one two thˇree four").await; } + + #[gpui::test] + async fn test_next_line_start(cx: &mut gpui::TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + cx.set_shared_state("ˇone\n two\nthree").await; + cx.simulate_shared_keystrokes(["enter"]).await; + cx.assert_shared_state("one\n ˇtwo\nthree").await; + } } diff --git a/crates/vim/test_data/test_next_line_start.json b/crates/vim/test_data/test_next_line_start.json new file mode 100644 index 0000000000..90ed4a4f03 --- /dev/null +++ b/crates/vim/test_data/test_next_line_start.json @@ -0,0 +1,3 @@ +{"Put":{"state":"ˇone\n two\nthree"}} +{"Key":"enter"} +{"Get":{"state":"one\n ˇtwo\nthree","mode":"Normal"}}