From 8de67fd9d94e878f9e59537cad5fa0a84e176f14 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 20 Sep 2023 11:14:00 -0600 Subject: [PATCH] Fix vim panic when over-shooting with j --- crates/vim/src/motion.rs | 2 +- crates/vim/src/test.rs | 20 ++++++++++++++++++++ crates/vim/test_data/test_folds_panic.json | 12 ++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 crates/vim/test_data/test_folds_panic.json diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index 08256bffb1..fbec127843 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -533,7 +533,7 @@ fn down( let new_row = cmp::min( start.row() + times as u32, - map.buffer_snapshot.max_point().row, + map.fold_snapshot.max_point().row(), ); let new_col = cmp::min(goal_column, map.fold_snapshot.line_len(new_row)); let point = map.fold_point_to_display_point( diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 559e065694..e43b0ab22b 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -575,6 +575,26 @@ async fn test_folds(cx: &mut gpui::TestAppContext) { .await; } +#[gpui::test] +async fn test_folds_panic(cx: &mut gpui::TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + cx.set_neovim_option("foldmethod=manual").await; + + cx.set_shared_state(indoc! { " + fn boop() { + ˇbarp() + bazp() + } + "}) + .await; + cx.simulate_shared_keystrokes(["shift-v", "j", "z", "f"]) + .await; + cx.simulate_shared_keystrokes(["escape"]).await; + cx.simulate_shared_keystrokes(["g", "g"]).await; + cx.simulate_shared_keystrokes(["5", "d", "j"]).await; + cx.assert_shared_state(indoc! { "ˇ"}).await; +} + #[gpui::test] async fn test_clear_counts(cx: &mut gpui::TestAppContext) { let mut cx = NeovimBackedTestContext::new(cx).await; diff --git a/crates/vim/test_data/test_folds_panic.json b/crates/vim/test_data/test_folds_panic.json new file mode 100644 index 0000000000..cfa0696794 --- /dev/null +++ b/crates/vim/test_data/test_folds_panic.json @@ -0,0 +1,12 @@ +{"SetOption":{"value":"foldmethod=manual"}} +{"Put":{"state":"fn boop() {\n ˇbarp()\n bazp()\n}\n"}} +{"Key":"shift-v"} +{"Key":"j"} +{"Key":"z"} +{"Key":"f"} +{"Key":"escape"} +{"Key":"g"} +{"Key":"g"} +{"Key":"5"} +{"Key":"d"} +{"Key":"j"}