Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
vim: Fix visual object expands (#28301)
0x2CAb04f7a4c7c4d
diff --git a/crates/vim/src/visual.rs b/crates/vim/src/visual.rsindex 6fcbf74970a..adb288395e7 100644--- a/crates/vim/src/visual.rs+++ b/crates/vim/src/visual.rs@@ -386,8 +386,20 @@ impl Vim {|| movement::right(map, selection.start) == selection.end;if expand_both_ways {- selection.start = range.start;- selection.end = range.end;+ if selection.start == range.start+ && selection.end == range.end+ && object.always_expands_both_ways()+ {+ if let Some(range) =+ object.range(map, selection.clone(), around)+ {+ selection.start = range.start;+ selection.end = range.end;+ }+ } else {+ selection.start = range.start;+ selection.end = range.end;+ }} else if selection.reversed {selection.start = range.start;} else {@@ -1419,6 +1431,62 @@ mod test {.assert_eq("«ˇhello in a word» again.");}+ #[gpui::test]+ async fn test_visual_object_expands(cx: &mut gpui::TestAppContext) {+ let mut cx = NeovimBackedTestContext::new(cx).await;++ cx.set_shared_state(indoc! {+ "{+ {+ ˇ }+ }+ {+ }+ "+ })+ .await;+ cx.simulate_shared_keystrokes("v l").await;+ cx.shared_state().await.assert_eq(indoc! {+ "{+ {+ « }ˇ»+ }+ {+ }+ "+ });+ cx.simulate_shared_keystrokes("a {").await;+ cx.shared_state().await.assert_eq(indoc! {+ "{+ «{+ }ˇ»+ }+ {+ }+ "+ });+ cx.simulate_shared_keystrokes("a {").await;+ cx.shared_state().await.assert_eq(indoc! {+ "«{+ {+ }+ }ˇ»+ {+ }+ "+ });+ // cx.simulate_shared_keystrokes("a {").await;+ // cx.shared_state().await.assert_eq(indoc! {+ // "{+ // «{+ // }ˇ»+ // }+ // {+ // }+ // "+ // });+ }+#[gpui::test]async fn test_mode_across_command(cx: &mut gpui::TestAppContext) {let mut cx = VimTestContext::new(cx, true).await;diff --git a/crates/vim/test_data/test_visual_object_expands.json b/crates/vim/test_data/test_visual_object_expands.jsonnew file mode 100644index 00000000000..ea285ea5be0--- /dev/null+++ b/crates/vim/test_data/test_visual_object_expands.json@@ -0,0 +1,10 @@+{"Put":{"state":"{\n {\n ˇ }\n}\n{\n}\n"}}+{"Key":"v"}+{"Key":"l"}+{"Get":{"state":"{\n {\n « }ˇ»\n}\n{\n}\n","mode":"Visual"}}+{"Key":"a"}+{"Key":"{"}+{"Get":{"state":"{\n «{\n }ˇ»\n}\n{\n}\n","mode":"Visual"}}+{"Key":"a"}+{"Key":"{"}+{"Get":{"state":"«{\n {\n }\n}ˇ»\n{\n}\n","mode":"Visual"}}