Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
vim: Increment search right (#10866)
Hendrik Sollich604857ed2e8a
diff --git a/crates/vim/src/normal/increment.rs b/crates/vim/src/normal/increment.rsindex e70fce99e1c..0ceb7c5a6d4 100644--- a/crates/vim/src/normal/increment.rs+++ b/crates/vim/src/normal/increment.rs@@ -117,13 +117,16 @@ fn find_number() -> Option<(Range<Point>, String, u32)> {let mut offset = start.to_offset(snapshot);- // go backwards to the start of any number the selection is within- for ch in snapshot.reversed_chars_at(offset) {- if ch.is_ascii_digit() || ch == '-' || ch == 'b' || ch == 'x' {- offset -= ch.len_utf8();- continue;+ let ch0 = snapshot.chars_at(offset).next();+ if ch0.as_ref().is_some_and(char::is_ascii_digit) || matches!(ch0, Some('-' | 'b' | 'x')) {+ // go backwards to the start of any number the selection is within+ for ch in snapshot.reversed_chars_at(offset) {+ if ch.is_ascii_digit() || ch == '-' || ch == 'b' || ch == 'x' {+ offset -= ch.len_utf8();+ continue;+ }+ break;}- break;}let mut begin = None;@@ -217,6 +220,48 @@ mod test {.await;}+ #[gpui::test]+ async fn test_increment_with_dot(cx: &mut gpui::TestAppContext) {+ let mut cx = NeovimBackedTestContext::new(cx).await;++ cx.set_shared_state(indoc! {"+ 1ˇ.2+ "})+ .await;++ cx.simulate_shared_keystrokes(["ctrl-a"]).await;+ cx.assert_shared_state(indoc! {"+ 1.ˇ3+ "})+ .await;+ cx.simulate_shared_keystrokes(["ctrl-x"]).await;+ cx.assert_shared_state(indoc! {"+ 1.ˇ2+ "})+ .await;+ }++ #[gpui::test]+ async fn test_increment_with_two_dots(cx: &mut gpui::TestAppContext) {+ let mut cx = NeovimBackedTestContext::new(cx).await;++ cx.set_shared_state(indoc! {"+ 111.ˇ.2+ "})+ .await;++ cx.simulate_shared_keystrokes(["ctrl-a"]).await;+ cx.assert_shared_state(indoc! {"+ 111..ˇ3+ "})+ .await;+ cx.simulate_shared_keystrokes(["ctrl-x"]).await;+ cx.assert_shared_state(indoc! {"+ 111..ˇ2+ "})+ .await;+ }+#[gpui::test]async fn test_increment_radix(cx: &mut gpui::TestAppContext) {let mut cx = NeovimBackedTestContext::new(cx).await;diff --git a/crates/vim/test_data/test_increment_with_dot.json b/crates/vim/test_data/test_increment_with_dot.jsonnew file mode 100644index 00000000000..b5c5b0914e2--- /dev/null+++ b/crates/vim/test_data/test_increment_with_dot.json@@ -0,0 +1,5 @@+{"Put":{"state":"1ˇ.2\n"}}+{"Key":"ctrl-a"}+{"Get":{"state":"1.ˇ3\n","mode":"Normal"}}+{"Key":"ctrl-x"}+{"Get":{"state":"1.ˇ2\n","mode":"Normal"}}diff --git a/crates/vim/test_data/test_increment_with_two_dots.json b/crates/vim/test_data/test_increment_with_two_dots.jsonnew file mode 100644index 00000000000..38b38f10053--- /dev/null+++ b/crates/vim/test_data/test_increment_with_two_dots.json@@ -0,0 +1,5 @@+{"Put":{"state":"111.ˇ.2\n"}}+{"Key":"ctrl-a"}+{"Get":{"state":"111..ˇ3\n","mode":"Normal"}}+{"Key":"ctrl-x"}+{"Get":{"state":"111..ˇ2\n","mode":"Normal"}}