Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
vim: Fix Escape not dismissing release notes notifications (#61759)
ᴀᴍᴛᴏᴀᴇʀd88f68217b37
diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.jsonindex 3acbbc73dad..955ffecb102 100644--- a/assets/keymaps/vim.json+++ b/assets/keymaps/vim.json@@ -435,6 +435,21 @@"ctrl-[": "editor::Cancel",},},+ // Vim/Helix consume Escape before menu::Cancel can dismiss notifications. macOS (Ctrl-C) and Linux+ // (Ctrl-Escape) have alternatives, but Windows does not, so try menu::Cancel first on Windows and+ // let Escape fall through when no notification is shown.+ {+ "context": "Editor && mode == full && VimControl && vim_mode == normal && !menu && os == windows",+ "bindings": {+ "escape": "menu::Cancel",+ },+ },+ {+ "context": "Editor && mode == full && VimControl && vim_mode == helix_normal && !menu && !BufferSearchBar && os == windows",+ "bindings": {+ "escape": "menu::Cancel",+ },+ },{"context": "vim_mode == helix_select && !menu && !BufferSearchBar","bindings": {diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rsindex 4a874591f72..b4cac5772c4 100644--- a/crates/vim/src/test.rs+++ b/crates/vim/src/test.rs@@ -14,6 +14,8 @@ use editor::{test::editor_test_context::EditorTestContext,};use futures::StreamExt;+#[cfg(target_os = "windows")]+use gpui::AppContext as _;use gpui::{KeyBinding, Modifiers, MouseButton, TestAppContext, px};use itertools::Itertools;use language::{CursorShape, Language, LanguageConfig, Point};@@ -29,6 +31,8 @@ use project::FakeFs;use search::BufferSearchBar;use search::{ProjectSearchView, project_search};use serde_json::json;+#[cfg(target_os = "windows")]+use workspace::notifications::{NotificationId, simple_message_notification::MessageNotification};use workspace::{DeploySearch, MultiWorkspace};use crate::{PushSneak, PushSneakBackward, VimAddon, insert::NormalBefore, motion, state::Mode};@@ -383,6 +387,46 @@ async fn test_escape_cancels(cx: &mut gpui::TestAppContext) {cx.assert_state("aˇbc", Mode::Normal);}+#[cfg(target_os = "windows")]+#[gpui::test]+async fn test_escape_dismisses_workspace_notification_in_normal_modes(+ cx: &mut gpui::TestAppContext,+) {+ struct VimEscapeNotification;+ struct HelixEscapeNotification;++ let mut cx = VimTestContext::new(cx, true).await;+ let notification_ids =+ |cx: &mut VimTestContext| cx.workspace(|workspace, _, _| workspace.notification_ids());++ for (mode, notification_id) in [+ (+ Mode::Normal,+ NotificationId::unique::<VimEscapeNotification>(),+ ),+ (+ Mode::HelixNormal,+ NotificationId::unique::<HelixEscapeNotification>(),+ ),+ ] {+ if mode == Mode::HelixNormal {+ cx.enable_helix();+ }+ cx.set_state("aˇbˇc", mode);+ cx.workspace(|workspace, _, cx| {+ workspace.show_notification(notification_id.clone(), cx, |cx| {+ cx.new(|cx| MessageNotification::new("Test notification", cx))+ });+ });++ assert_eq!(notification_ids(&mut cx), vec![notification_id]);+ cx.simulate_keystrokes("escape");++ assert!(notification_ids(&mut cx).is_empty());+ cx.assert_state("aˇbˇc", mode);+ }+}+#[perf]#[gpui::test]async fn test_selection_on_search(cx: &mut gpui::TestAppContext) {