Bind cmd-? to assistant::toggle_focus

Nathan Sobo and Antonio Scandurra created

Bypass system help menu shortcut at the app delegate level to achieve this.

Co-Authored-By: Antonio Scandurra <antonio@zed.dev>

Change summary

assets/keymaps/default.json              |  1 +
crates/gpui/src/app.rs                   | 23 +++++++++++++++++++++++
crates/gpui/src/platform/mac/platform.rs |  1 -
crates/zed/src/main.rs                   |  2 --
4 files changed, 24 insertions(+), 3 deletions(-)

Detailed changes

assets/keymaps/default.json 🔗

@@ -408,6 +408,7 @@
       "cmd-shift-p": "command_palette::Toggle",
       "cmd-shift-m": "diagnostics::Deploy",
       "cmd-shift-e": "project_panel::ToggleFocus",
+      "cmd-?": "assistant::ToggleFocus",
       "cmd-alt-s": "workspace::SaveAll",
       "cmd-k m": "language_selector::Toggle"
     }

crates/gpui/src/app.rs 🔗

@@ -152,6 +152,29 @@ impl App {
             asset_source,
         ))));
 
+        foreground_platform.on_event(Box::new({
+            let cx = app.0.clone();
+            move |event| {
+                if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = &event {
+                    // Allow system menu "cmd-?" shortcut to be overridden
+                    if keystroke.cmd
+                        && !keystroke.shift
+                        && !keystroke.alt
+                        && !keystroke.function
+                        && keystroke.key == "?"
+                    {
+                        if cx
+                            .borrow_mut()
+                            .update_active_window(|cx| cx.dispatch_keystroke(keystroke))
+                            .unwrap_or(false)
+                        {
+                            return true;
+                        }
+                    }
+                }
+                false
+            }
+        }));
         foreground_platform.on_quit(Box::new({
             let cx = app.0.clone();
             move || {

crates/gpui/src/platform/mac/platform.rs 🔗

@@ -939,7 +939,6 @@ extern "C" fn send_event(this: &mut Object, _sel: Sel, native_event: id) {
                 }
             }
         }
-
         msg_send![super(this, class!(NSApplication)), sendEvent: native_event]
     }
 }

crates/zed/src/main.rs 🔗

@@ -72,8 +72,6 @@ fn main() {
     let installation_id = app.background().block(installation_id()).ok();
     init_panic_hook(&app, installation_id.clone());
 
-    app.background();
-
     load_embedded_fonts(&app);
 
     let fs = Arc::new(RealFs);