From 8fc2431a2ac13c32ffd45983eedd478bc41789f0 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 26 Feb 2024 22:54:02 -0700 Subject: [PATCH] vim: Keep multi-cursor on escape (#8464) Release Notes: - vim: Preserve multiple selections when returning to normal mode. /cc @mrnugget --- crates/editor/src/editor.rs | 32 +++++++++++++++++++++----------- crates/vim/src/insert.rs | 2 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index f32273b6e375b21cf2836e77c36ddddf8070791e..6fb25c542623a2082dfb94d2e729dedb755c3f91 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2341,38 +2341,48 @@ impl Editor { } pub fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext) { - 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) -> 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) { diff --git a/crates/vim/src/insert.rs b/crates/vim/src/insert.rs index 6ac3f28695b8bf600d5f3bf620087f4612ec71b4..064c4b67a0359976480da6dc04c08b5f9c5cf6ef 100644 --- a/crates/vim/src/insert.rs +++ b/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);