Add o/O for flipping selection

Conrad Irwin created

Change summary

assets/keymaps/vim.json  |  2 ++
crates/vim/src/visual.rs | 16 +++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)

Detailed changes

assets/keymaps/vim.json 🔗

@@ -360,6 +360,8 @@
     "context": "Editor && vim_mode == visual && !VimWaiting",
     "bindings": {
       "u": "editor::Undo",
+      "o": "vim::OtherEnd",
+      "shift-o": "vim::OtherEnd",
       "c": "vim::VisualChange",
       "d": "vim::VisualDelete",
       "x": "vim::VisualDelete",

crates/vim/src/visual.rs 🔗

@@ -24,13 +24,15 @@ actions!(
         VisualDelete,
         VisualChange,
         VisualYank,
-        VisualPaste
+        VisualPaste,
+        OtherEnd,
     ]
 );
 
 pub fn init(cx: &mut AppContext) {
     cx.add_action(toggle_visual);
     cx.add_action(toggle_visual_line);
+    cx.add_action(other_end);
     cx.add_action(change);
     cx.add_action(delete);
     cx.add_action(yank);
@@ -150,6 +152,18 @@ pub fn toggle_visual_line(
     })
 }
 
+pub fn other_end(_: &mut Workspace, _: &OtherEnd, cx: &mut ViewContext<Workspace>) {
+    Vim::update(cx, |vim, cx| {
+        vim.update_active_editor(cx, |editor, cx| {
+            editor.change_selections(None, cx, |s| {
+                s.move_with(|_, selection| {
+                    selection.reversed = !selection.reversed;
+                })
+            })
+        })
+    });
+}
+
 pub fn change(_: &mut Workspace, _: &VisualChange, cx: &mut ViewContext<Workspace>) {
     Vim::update(cx, |vim, cx| {
         vim.update_active_editor(cx, |editor, cx| {