Fix zed-industries/community#1950

Conrad Irwin created

Change summary

crates/vim/src/visual.rs                         | 36 +++++++++++++----
crates/vim/test_data/test_visual_block_mode.json |  6 +++
2 files changed, 33 insertions(+), 9 deletions(-)

Detailed changes

crates/vim/src/visual.rs 🔗

@@ -126,10 +126,15 @@ pub fn visual_block_motion(
         let map = &s.display_map();
         let mut head = s.newest_anchor().head().to_display_point(map);
         let mut tail = s.oldest_anchor().tail().to_display_point(map);
-        let mut goal = s.newest_anchor().goal;
 
-        let was_reversed = tail.column() > head.column();
+        let (start, end) = match s.newest_anchor().goal {
+            SelectionGoal::ColumnRange { start, end } if preserve_goal => (start, end),
+            SelectionGoal::Column(start) if preserve_goal => (start, start + 1),
+            _ => (tail.column(), head.column()),
+        };
+        let goal = SelectionGoal::ColumnRange { start, end };
 
+        let was_reversed = tail.column() > head.column();
         if !was_reversed && !preserve_goal {
             head = movement::saturating_left(map, head);
         }
@@ -149,13 +154,6 @@ pub fn visual_block_motion(
             head = movement::saturating_right(map, head)
         }
 
-        let (start, end) = match goal {
-            SelectionGoal::ColumnRange { start, end } if preserve_goal => (start, end),
-            SelectionGoal::Column(start) if preserve_goal => (start, start + 1),
-            _ => (tail.column(), head.column()),
-        };
-        goal = SelectionGoal::ColumnRange { start, end };
-
         let columns = if is_reversed {
             head.column()..tail.column()
         } else if head.column() == tail.column() {
@@ -791,6 +789,26 @@ mod test {
             "
         })
         .await;
+
+        //https://github.com/zed-industries/community/issues/1950
+        cx.set_shared_state(indoc! {
+            "Theˇ quick brown
+
+            fox jumps over
+            the lazy dog
+            "
+        })
+        .await;
+        cx.simulate_shared_keystrokes(["l", "ctrl-v", "j", "j"])
+            .await;
+        cx.assert_shared_state(indoc! {
+            "The «qˇ»uick brown
+
+            fox «jˇ»umps over
+            the lazy dog
+            "
+        })
+        .await;
     }
 
     #[gpui::test]

crates/vim/test_data/test_visual_block_mode.json 🔗

@@ -30,3 +30,9 @@
 {"Key":"o"}
 {"Key":"escape"}
 {"Get":{"state":"Theˇouick\nbroo\nfoxo\njumo over the\n\nlazy dog\n","mode":"Normal"}}
+{"Put":{"state":"Theˇ quick brown\n\nfox jumps over\nthe lazy dog\n"}}
+{"Key":"l"}
+{"Key":"ctrl-v"}
+{"Key":"j"}
+{"Key":"j"}
+{"Get":{"state":"The «qˇ»uick brown\n\nfox «jˇ»umps over\nthe lazy dog\n","mode":"VisualBlock"}}