diff --git a/crates/vim/src/object.rs b/crates/vim/src/object.rs index 2392c4a025..fc011b0b91 100644 --- a/crates/vim/src/object.rs +++ b/crates/vim/src/object.rs @@ -838,13 +838,16 @@ fn surrounding_markers( } if opening.is_none() { - for ((ch, range), (before_ch, _)) in movement::chars_before(map, point).tuple_windows() { + let mut chars_before = movement::chars_before(map, point).peekable(); + while let Some((ch, range)) = chars_before.next() { if ch == '\n' && !search_across_lines { break; } - if before_ch == '\\' { - continue; + if let Some((before_ch, _)) = chars_before.peek() { + if *before_ch == '\\' { + continue; + } } if ch == open_marker { @@ -1209,6 +1212,24 @@ mod test { let mut cx = NeovimBackedTestContext::new(cx).await; cx.set_shared_wrap(12).await; + cx.set_shared_state(indoc! { + "\"ˇhello world\"!" + }) + .await; + cx.simulate_shared_keystrokes("v i \"").await; + cx.shared_state().await.assert_eq(indoc! { + "\"«hello worldˇ»\"!" + }); + + cx.set_shared_state(indoc! { + "\"hˇello world\"!" + }) + .await; + cx.simulate_shared_keystrokes("v i \"").await; + cx.shared_state().await.assert_eq(indoc! { + "\"«hello worldˇ»\"!" + }); + cx.set_shared_state(indoc! { "helˇlo \"world\"!" }) diff --git a/crates/vim/test_data/test_singleline_surrounding_character_objects.json b/crates/vim/test_data/test_singleline_surrounding_character_objects.json index f7f95ce697..2499786c72 100644 --- a/crates/vim/test_data/test_singleline_surrounding_character_objects.json +++ b/crates/vim/test_data/test_singleline_surrounding_character_objects.json @@ -1,5 +1,15 @@ {"SetOption":{"value":"wrap"}} {"SetOption":{"value":"columns=12"}} +{"Put":{"state":"\"ˇhello world\"!"}} +{"Key":"v"} +{"Key":"i"} +{"Key":"\""} +{"Get":{"state":"\"«hello worldˇ»\"!","mode":"Visual"}} +{"Put":{"state":"\"hˇello world\"!"}} +{"Key":"v"} +{"Key":"i"} +{"Key":"\""} +{"Get":{"state":"\"«hello worldˇ»\"!","mode":"Visual"}} {"Put":{"state":"helˇlo \"world\"!"}} {"Key":"v"} {"Key":"i"}