From a4e77af571f720ca4cc1e1f17cd66eb1f69f1470 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 4 Oct 2023 15:13:01 -0600 Subject: [PATCH] Fix panic in increment --- crates/vim/src/normal/increment.rs | 14 ++++++++++---- crates/vim/test_data/test_increment_radix.json | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/vim/src/normal/increment.rs b/crates/vim/src/normal/increment.rs index d7f3d1f904..9d62f8ab7b 100644 --- a/crates/vim/src/normal/increment.rs +++ b/crates/vim/src/normal/increment.rs @@ -78,10 +78,14 @@ fn increment(vim: &mut Vim, mut delta: i32, step: i32, cx: &mut WindowContext) { 2 => format!("{:b}", result), _ => unreachable!(), }; - if selection.is_empty() { - new_anchors.push((false, snapshot.anchor_after(range.end))) - } - edits.push((range, replace)); + edits.push((range.clone(), replace)); + } + if selection.is_empty() { + new_anchors.push((false, snapshot.anchor_after(range.end))) + } + } else { + if selection.is_empty() { + new_anchors.push((true, snapshot.anchor_after(start))) } } } @@ -226,6 +230,8 @@ mod test { cx.assert_matches_neovim("(ˇ0b10f)", ["ctrl-a"], "(0b1ˇ1f)") .await; cx.assert_matches_neovim("ˇ-1", ["ctrl-a"], "ˇ0").await; + cx.assert_matches_neovim("banˇana", ["ctrl-a"], "banˇana") + .await; } #[gpui::test] diff --git a/crates/vim/test_data/test_increment_radix.json b/crates/vim/test_data/test_increment_radix.json index f9379a7195..0f41c01599 100644 --- a/crates/vim/test_data/test_increment_radix.json +++ b/crates/vim/test_data/test_increment_radix.json @@ -13,3 +13,6 @@ {"Put":{"state":"ˇ-1"}} {"Key":"ctrl-a"} {"Get":{"state":"ˇ0","mode":"Normal"}} +{"Put":{"state":"banˇana"}} +{"Key":"ctrl-a"} +{"Get":{"state":"banˇana","mode":"Normal"}}