Add open vim keymap command (#9953)

Mehmet Efe Akรงa and Marshall Bowers created

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 <elliott.codes@gmail.com>

Change summary

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(-)

Detailed changes

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>) {
         })
     });
 
+    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);

crates/workspace/src/workspace.rs ๐Ÿ”—

@@ -521,6 +521,11 @@ pub enum Event {
     ContactRequestedJoin(u64),
     WorkspaceCreated(WeakView<Workspace>),
     SpawnTask(SpawnInTerminal),
+    OpenBundledFile {
+        text: Cow<'static, str>,
+        title: &'static str,
+        language: &'static str,
+    },
     ZoomChanged,
 }
 

crates/zed/src/zed.rs ๐Ÿ”—

@@ -112,10 +112,16 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
         let center_pane = workspace.active_pane().clone();
         initialize_pane(workspace, &center_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();