vim: Keep multi-cursor on escape (#8464)

Conrad Irwin created

Release Notes:

- vim: Preserve multiple selections when returning to normal mode.

/cc @mrnugget

Change summary

crates/editor/src/editor.rs | 32 +++++++++++++++++++++-----------
crates/vim/src/insert.rs    |  2 +-
2 files changed, 22 insertions(+), 12 deletions(-)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -2341,38 +2341,48 @@ impl Editor {
     }
 
     pub fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
-        if self.take_rename(false, cx).is_some() {
+        if self.dismiss_menus_and_popups(cx) {
             return;
         }
 
+        if self.mode == EditorMode::Full {
+            if self.change_selections(Some(Autoscroll::fit()), cx, |s| s.try_cancel()) {
+                return;
+            }
+        }
+
+        cx.propagate();
+    }
+
+    pub fn dismiss_menus_and_popups(&mut self, cx: &mut ViewContext<Self>) -> bool {
+        if self.take_rename(false, cx).is_some() {
+            return true;
+        }
+
         if hide_hover(self, cx) {
-            return;
+            return true;
         }
 
         if self.hide_context_menu(cx).is_some() {
-            return;
+            return true;
         }
 
         if self.discard_copilot_suggestion(cx) {
-            return;
+            return true;
         }
 
         if self.snippet_stack.pop().is_some() {
-            return;
+            return true;
         }
 
         if self.mode == EditorMode::Full {
             if self.active_diagnostics.is_some() {
                 self.dismiss_diagnostics(cx);
-                return;
-            }
-
-            if self.change_selections(Some(Autoscroll::fit()), cx, |s| s.try_cancel()) {
-                return;
+                return true;
             }
         }
 
-        cx.propagate();
+        false
     }
 
     pub fn handle_input(&mut self, text: &str, cx: &mut ViewContext<Self>) {

crates/vim/src/insert.rs 🔗

@@ -16,7 +16,7 @@ fn normal_before(_: &mut Workspace, action: &NormalBefore, cx: &mut ViewContext<
         vim.stop_recording_immediately(action.boxed_clone());
         if count <= 1 || vim.workspace_state.replaying {
             vim.update_active_editor(cx, |_, editor, cx| {
-                editor.cancel(&Default::default(), cx);
+                editor.dismiss_menus_and_popups(cx);
                 editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
                     s.move_cursors_with(|map, mut cursor, _| {
                         *cursor.column_mut() = cursor.column().saturating_sub(1);