From f369e9a48be652797b81737b86fde54d97ee0613 Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Fri, 26 Jan 2024 16:58:48 -0800 Subject: [PATCH 1/2] vim: fix dtx when x is immediately to the right --- crates/vim/src/motion.rs | 19 +++++++++++-------- crates/vim/src/normal/delete.rs | 7 +++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index 01d8bec569..d7a46888cc 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -434,10 +434,13 @@ impl Motion { SelectionGoal::None, ), Matching => (matching(map, point), SelectionGoal::None), - FindForward { before, char } => ( - find_forward(map, point, *before, *char, times), - SelectionGoal::None, - ), + FindForward { before, char } => { + if let Some(new_point) = find_forward(map, point, *before, *char, times) { + return Some((new_point, SelectionGoal::None)); + } else { + return None; + } + } FindBackward { after, char } => ( find_backward(map, point, *after, *char, times), SelectionGoal::None, @@ -882,7 +885,7 @@ fn find_forward( before: bool, target: char, times: usize, -) -> DisplayPoint { +) -> Option { let mut to = from; let mut found = false; @@ -897,12 +900,12 @@ fn find_forward( if found { if before && to.column() > 0 { *to.column_mut() -= 1; - map.clip_point(to, Bias::Left) + Some(map.clip_point(to, Bias::Left)) } else { - to + Some(to) } } else { - from + None } } diff --git a/crates/vim/src/normal/delete.rs b/crates/vim/src/normal/delete.rs index ed9cdf19fa..cbcdcadca9 100644 --- a/crates/vim/src/normal/delete.rs +++ b/crates/vim/src/normal/delete.rs @@ -472,4 +472,11 @@ mod test { the ˇlazy dog"}) .await; } + + #[gpui::test] + async fn test_delete_to_adjacent_character(cx: &mut gpui::TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + cx.assert_neovim_compatible("ˇax", ["d", "t", "x"]).await; + cx.assert_neovim_compatible("aˇx", ["d", "t", "x"]).await; + } } From 5b9f15e0750edb32e1449c78b9d1c7114d7aceed Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Fri, 26 Jan 2024 20:02:59 -0800 Subject: [PATCH 2/2] add test_data --- .../test_data/test_delete_to_adjacent_character.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 crates/vim/test_data/test_delete_to_adjacent_character.json diff --git a/crates/vim/test_data/test_delete_to_adjacent_character.json b/crates/vim/test_data/test_delete_to_adjacent_character.json new file mode 100644 index 0000000000..130719c890 --- /dev/null +++ b/crates/vim/test_data/test_delete_to_adjacent_character.json @@ -0,0 +1,10 @@ +{"Put":{"state":"ˇax"}} +{"Key":"d"} +{"Key":"t"} +{"Key":"x"} +{"Get":{"state":"ˇx","mode":"Normal"}} +{"Put":{"state":"aˇx"}} +{"Key":"d"} +{"Key":"t"} +{"Key":"x"} +{"Get":{"state":"aˇx","mode":"Normal"}}