From 018a2a29eac9e8e487c75c6a2a5020f0d83fe2ea Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 11 Jul 2024 12:01:56 -0600 Subject: [PATCH] vim: Fix `c` when range ends in a multibyte character (#14139) Release Notes: - vim: Fixed `c ` omitting trailing multibyte characters ([#13909](https://github.com/zed-industries/zed/issues/13909)). --- crates/vim/src/motion.rs | 2 +- crates/vim/src/test.rs | 13 +++++++++++++ crates/vim/test_data/test_find_multibyte.json | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 crates/vim/test_data/test_find_multibyte.json diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index c99901e2fa..ed8640ecbc 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -890,7 +890,7 @@ impl Motion { } if inclusive && selection.end.column() < map.line_len(selection.end.row()) { - *selection.end.column_mut() += 1; + selection.end = movement::saturating_right(map, selection.end) } } Some(selection.start..selection.end) diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 7c59d5541a..b40a5cd9ac 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -1266,3 +1266,16 @@ async fn test_toggle_comments(cx: &mut gpui::TestAppContext) { Mode::Normal, ); } + +#[gpui::test] +async fn test_find_multibyte(cx: &mut gpui::TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + + cx.set_shared_state(r#""#) + .await; + + cx.simulate_shared_keystrokes("c t < o escape").await; + cx.shared_state() + .await + .assert_eq(r#""#); +} diff --git a/crates/vim/test_data/test_find_multibyte.json b/crates/vim/test_data/test_find_multibyte.json new file mode 100644 index 0000000000..710a89aede --- /dev/null +++ b/crates/vim/test_data/test_find_multibyte.json @@ -0,0 +1,7 @@ +{"Put":{"state":""}} +{"Key":"c"} +{"Key":"t"} +{"Key":"<"} +{"Key":"o"} +{"Key":"escape"} +{"Get":{"state":"","mode":"Normal"}}