From 762fa9b3c79d224236a2e6e4cdb98589ff0c9eac Mon Sep 17 00:00:00 2001 From: AidanV <84053180+AidanV@users.noreply.github.com> Date: Tue, 14 Oct 2025 11:07:26 -0700 Subject: [PATCH] vim: Decrease max vim count (#40059) Release Notes: - Fixes bug were typing `9999999999999999999j` (19 9's) would go up instead of down - Max Vim count is now isize::MAX - 1 --- crates/vim/src/test.rs | 16 +++++++ crates/vim/src/vim.rs | 2 + crates/vim/test_data/test_jk_max_count.json | 47 +++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 crates/vim/test_data/test_jk_max_count.json diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 2f130356a70c0ee8cff1803112a1caec87c45469..297ef6447368bdc35ed3935b25dcd687f0e9f252 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -13,6 +13,7 @@ use editor::{ }; use futures::StreamExt; use gpui::{KeyBinding, Modifiers, MouseButton, TestAppContext, px}; +use itertools::Itertools; use language::Point; pub use neovim_backed_test_context::*; use settings::SettingsStore; @@ -974,6 +975,21 @@ async fn test_jk_delay(cx: &mut gpui::TestAppContext) { cx.assert_state("jˇkhello", Mode::Normal); } +#[perf] +#[gpui::test] +async fn test_jk_max_count(cx: &mut gpui::TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + + cx.set_shared_state("1\nˇ2\n3").await; + cx.simulate_shared_keystrokes("9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 j") + .await; + cx.shared_state().await.assert_eq("1\n2\nˇ3"); + + let number: String = usize::MAX.to_string().split("").join(" "); + cx.simulate_shared_keystrokes(&format!("{number} k")).await; + cx.shared_state().await.assert_eq("ˇ1\n2\n3"); +} + #[perf] #[gpui::test] async fn test_comma_w(cx: &mut gpui::TestAppContext) { diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 4999a4b04c2005ad2371b4e82c7f23578269c7bc..d4c81737fdbda08a1a2861c184035a784960fe52 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -1525,6 +1525,7 @@ impl Vim { post_count .checked_mul(10) .and_then(|post_count| post_count.checked_add(number)) + .filter(|post_count| *post_count < isize::MAX as usize) .unwrap_or(post_count), ) } else { @@ -1534,6 +1535,7 @@ impl Vim { pre_count .checked_mul(10) .and_then(|pre_count| pre_count.checked_add(number)) + .filter(|pre_count| *pre_count < isize::MAX as usize) .unwrap_or(pre_count), ) } diff --git a/crates/vim/test_data/test_jk_max_count.json b/crates/vim/test_data/test_jk_max_count.json new file mode 100644 index 0000000000000000000000000000000000000000..83eab46a18a74cb258c47c6b94f1ec01beeadf21 --- /dev/null +++ b/crates/vim/test_data/test_jk_max_count.json @@ -0,0 +1,47 @@ +{"Put":{"state":"1\nˇ2\n3"}} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"9"} +{"Key":"j"} +{"Get":{"state":"1\n2\nˇ3","mode":"Normal"}} +{"Key":""} +{"Key":"1"} +{"Key":"8"} +{"Key":"4"} +{"Key":"4"} +{"Key":"6"} +{"Key":"7"} +{"Key":"4"} +{"Key":"4"} +{"Key":"0"} +{"Key":"7"} +{"Key":"3"} +{"Key":"7"} +{"Key":"0"} +{"Key":"9"} +{"Key":"5"} +{"Key":"5"} +{"Key":"1"} +{"Key":"6"} +{"Key":"1"} +{"Key":"5"} +{"Key":""} +{"Key":"k"} +{"Get":{"state":"ˇ1\n2\n3","mode":"Normal"}}