linux: Add keyboard shortcuts for menus (#22074)
Closes #19837 This PR is a continuation of [linux: Implement Menus](https://github.com/zed-industries/zed/pull/21873) and should only be reviewed once the existing PR is merged. I created this as a separate PR as the existing PR was already reviewed but is yet to merge, and also it was my initial plan to do it in separate parts because of the scope of it. This will also help reviewing code faster. This PR adds two new types of keyboard shortcuts to make menu navigation easier: 1. `Alt + Z` for Zed, `Alt + F` for File, `Alt + S` for Selection, and so on to open a specific menu with this combination. This mimics VSCode and IntelliJ. 2. `Arrow Left/Right` when any menu is open. This will trigger the current menu to close, and the previous/next to open respectively. First and last element cycling is handled. `Arrow Up/Down` to navigate menu entries is already there in existing work. https://github.com/user-attachments/assets/976aea48-4e20-4c19-850d-4d205a4bead2 Release Notes: - Added keyboard navigation for menus on Linux (left/right). If you wish to open menus with keyboard shortcuts add the following to your user keymap: ```json { "context": "Workspace", "bindings": { "alt-z": ["app_menu::OpenApplicationMenu", "Zed"], "alt-f": ["app_menu::OpenApplicationMenu", "File"], "alt-e": ["app_menu::OpenApplicationMenu", "Edit"], "alt-s": ["app_menu::OpenApplicationMenu", "Selection"], "alt-v": ["app_menu::OpenApplicationMenu", "View"], "alt-g": ["app_menu::OpenApplicationMenu", "Go"], "alt-w": ["app_menu::OpenApplicationMenu", "Window"], "alt-h": ["app_menu::OpenApplicationMenu", "Help"] } } ``` --------- Co-authored-by: Peter Tripp <peter@zed.dev>
This commit is contained in:
parent
11ec25aedb
commit
bb24c085be
3 changed files with 143 additions and 11 deletions
|
@ -7,6 +7,10 @@ mod window_controls;
|
|||
mod stories;
|
||||
|
||||
use crate::application_menu::ApplicationMenu;
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
use crate::application_menu::{NavigateApplicationMenuInDirection, OpenApplicationMenu};
|
||||
|
||||
use crate::platforms::{platform_linux, platform_mac, platform_windows};
|
||||
use auto_update::AutoUpdateStatus;
|
||||
use call::ActiveCall;
|
||||
|
@ -53,7 +57,39 @@ actions!(
|
|||
pub fn init(cx: &mut AppContext) {
|
||||
cx.observe_new_views(|workspace: &mut Workspace, cx| {
|
||||
let item = cx.new_view(|cx| TitleBar::new("title-bar", workspace, cx));
|
||||
workspace.set_titlebar_item(item.into(), cx)
|
||||
workspace.set_titlebar_item(item.into(), cx);
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
workspace.register_action(|workspace, action: &OpenApplicationMenu, cx| {
|
||||
if let Some(titlebar) = workspace
|
||||
.titlebar_item()
|
||||
.and_then(|item| item.downcast::<TitleBar>().ok())
|
||||
{
|
||||
titlebar.update(cx, |titlebar, cx| {
|
||||
if let Some(ref menu) = titlebar.application_menu {
|
||||
menu.update(cx, |menu, cx| menu.open_menu(action, cx));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
workspace.register_action(
|
||||
|workspace, action: &NavigateApplicationMenuInDirection, cx| {
|
||||
if let Some(titlebar) = workspace
|
||||
.titlebar_item()
|
||||
.and_then(|item| item.downcast::<TitleBar>().ok())
|
||||
{
|
||||
titlebar.update(cx, |titlebar, cx| {
|
||||
if let Some(ref menu) = titlebar.application_menu {
|
||||
menu.update(cx, |menu, cx| {
|
||||
menu.navigate_menus_in_direction(action, cx)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
@ -138,7 +174,7 @@ impl Render for TitleBar {
|
|||
let mut render_project_items = true;
|
||||
title_bar
|
||||
.when_some(self.application_menu.clone(), |title_bar, menu| {
|
||||
render_project_items = !menu.read(cx).is_any_deployed();
|
||||
render_project_items = !menu.read(cx).all_menus_shown();
|
||||
title_bar.child(menu)
|
||||
})
|
||||
.when(render_project_items, |title_bar| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue