From 339b29ef17624aa1013e74420d599958195055fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Efe=20Ak=C3=A7a?= <13402668+mmtftr@users.noreply.github.com> Date: Thu, 11 Apr 2024 02:03:13 +0300 Subject: [PATCH] Add open vim keymap command (#9953) Release Notes: - Added a `vim: open default keymap` command to show the default Vim keymap ([#8593](https://github.com/zed-industries/zed/issues/8593)). Co-authored-by: Marshall Bowers --- crates/vim/src/vim.rs | 18 +++++++++++++++++- crates/workspace/src/workspace.rs | 5 +++++ crates/zed/src/zed.rs | 10 ++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index e8dc3bfe5b2e29de38703842a3be5fa55cbf5e31..55f961425cb9c5eec92dab071b4ee02b76372629 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -67,7 +67,15 @@ struct Number(usize); actions!( vim, - [Tab, Enter, Object, InnerObject, FindForward, FindBackward] + [ + Tab, + Enter, + Object, + InnerObject, + FindForward, + FindBackward, + OpenDefaultKeymap + ] ); // in the workspace namespace so it's not filtered out when vim is disabled. @@ -133,6 +141,14 @@ fn register(workspace: &mut Workspace, cx: &mut ViewContext) { }) }); + workspace.register_action(|_: &mut Workspace, _: &OpenDefaultKeymap, cx| { + cx.emit(workspace::Event::OpenBundledFile { + text: settings::vim_keymap(), + title: "Default Vim Bindings", + language: "JSON", + }); + }); + normal::register(workspace, cx); insert::register(workspace, cx); motion::register(workspace, cx); diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 5169b4cd88342533f003d06a444fac903464fceb..577346ea5604e07291fb51219de317d9b3de428b 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -521,6 +521,11 @@ pub enum Event { ContactRequestedJoin(u64), WorkspaceCreated(WeakView), SpawnTask(SpawnInTerminal), + OpenBundledFile { + text: Cow<'static, str>, + title: &'static str, + language: &'static str, + }, ZoomChanged, } diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 1954e33f94a39f0c7e0f735d8d222dd8afa1a296..cf68f8a0e9d1d30f00609daaa000df3471798850 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -112,10 +112,16 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { let center_pane = workspace.active_pane().clone(); initialize_pane(workspace, ¢er_pane, cx); cx.subscribe(&workspace_handle, { - move |workspace, _, event, cx| { - if let workspace::Event::PaneAdded(pane) = event { + move |workspace, _, event, cx| match event { + workspace::Event::PaneAdded(pane) => { initialize_pane(workspace, pane, cx); } + workspace::Event::OpenBundledFile { + text, + title, + language, + } => open_bundled_file(workspace, text.clone(), title, language, cx), + _ => {} } }) .detach();