Add space switching shortcuts

This commit is contained in:
2026-05-08 08:57:18 -04:00
parent 43ab4be548
commit cdb82bcace
7 changed files with 142 additions and 2 deletions
+5
View File
@@ -23,7 +23,9 @@ actions!(
OpenTaskManager,
Quit,
RestoreClosedTab,
SelectNextSpace,
SelectNextTab,
SelectPreviousSpace,
SelectPreviousTab,
SplitRight,
ToggleFavoriteTab,
@@ -59,6 +61,9 @@ fn main() {
MenuItem::separator(),
MenuItem::action("Restore Closed Tab", RestoreClosedTab),
MenuItem::separator(),
MenuItem::action("Next Space", SelectNextSpace),
MenuItem::action("Previous Space", SelectPreviousSpace),
MenuItem::separator(),
MenuItem::action("Open Downloads", OpenDownloads),
MenuItem::action("Open History", OpenHistory),
MenuItem::action("Open Task Manager", OpenTaskManager),
+1
View File
@@ -8,6 +8,7 @@ mod reading_list;
mod render;
mod sidebar;
mod site_permissions;
mod spaces;
mod splits;
mod tab_groups;
+2
View File
@@ -51,7 +51,9 @@ impl ElyShell {
.on_action(cx.listener(Self::on_open_settings))
.on_action(cx.listener(Self::on_open_task_manager))
.on_action(cx.listener(Self::on_restore_closed_tab))
.on_action(cx.listener(Self::on_select_next_space))
.on_action(cx.listener(Self::on_select_next_tab))
.on_action(cx.listener(Self::on_select_previous_space))
.on_action(cx.listener(Self::on_select_previous_tab))
.on_action(cx.listener(Self::on_split_right))
.on_action(cx.listener(Self::on_toggle_favorite_tab))
+34
View File
@@ -0,0 +1,34 @@
use gpui::{Context, Window};
use super::{ElyShell, ShellState};
use crate::{SelectNextSpace, SelectPreviousSpace};
impl ElyShell {
pub(super) fn on_select_next_space(
&mut self,
_: &SelectNextSpace,
window: &mut Window,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.select_next_space().is_ok()
{
self.sync_address_input(window, cx);
cx.notify();
}
}
pub(super) fn on_select_previous_space(
&mut self,
_: &SelectPreviousSpace,
window: &mut Window,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.select_previous_space().is_ok()
{
self.sync_address_input(window, cx);
cx.notify();
}
}
}
+51 -2
View File
@@ -4,8 +4,8 @@ use gpui::{App, KeyBinding};
use crate::{
CloseCurrentTab, FocusAddressBar, FocusCommandMode, OpenDownloads, OpenHistory, OpenNewTab,
OpenSettings, OpenTaskManager, Quit, RestoreClosedTab, SelectNextTab, SelectPreviousTab,
SplitRight, ToggleFavoriteTab, ToggleSidebar,
OpenSettings, OpenTaskManager, Quit, RestoreClosedTab, SelectNextSpace, SelectNextTab,
SelectPreviousSpace, SelectPreviousTab, SplitRight, ToggleFavoriteTab, ToggleSidebar,
};
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
@@ -30,6 +30,8 @@ pub(crate) enum ShortcutAction {
OpenNewTab,
CloseCurrentTab,
RestoreClosedTab,
SelectNextSpace,
SelectPreviousSpace,
SelectNextTab,
SelectPreviousTab,
SplitRight,
@@ -50,6 +52,8 @@ impl ShortcutAction {
Self::OpenNewTab => "New Tab",
Self::CloseCurrentTab => "Close Tab",
Self::RestoreClosedTab => "Restore Closed Tab",
Self::SelectNextSpace => "Next Space",
Self::SelectPreviousSpace => "Previous Space",
Self::SelectNextTab => "Next Tab",
Self::SelectPreviousTab => "Previous Tab",
Self::SplitRight => "Split Right",
@@ -69,6 +73,8 @@ impl ShortcutAction {
Self::OpenNewTab
| Self::CloseCurrentTab
| Self::RestoreClosedTab
| Self::SelectNextSpace
| Self::SelectPreviousSpace
| Self::SelectNextTab
| Self::SelectPreviousTab
| Self::SplitRight
@@ -87,6 +93,8 @@ impl ShortcutAction {
Self::OpenNewTab => Some(">new-tab"),
Self::CloseCurrentTab => Some(">close-tab"),
Self::RestoreClosedTab => Some(">restore-tab"),
Self::SelectNextSpace => None,
Self::SelectPreviousSpace => None,
Self::SelectNextTab => None,
Self::SelectPreviousTab => None,
Self::SplitRight => Some(">split-right"),
@@ -127,6 +135,8 @@ pub(crate) const SHORTCUT_ACTIONS: &[ShortcutAction] = &[
ShortcutAction::OpenNewTab,
ShortcutAction::CloseCurrentTab,
ShortcutAction::RestoreClosedTab,
ShortcutAction::SelectNextSpace,
ShortcutAction::SelectPreviousSpace,
ShortcutAction::SelectNextTab,
ShortcutAction::SelectPreviousTab,
ShortcutAction::SplitRight,
@@ -164,6 +174,10 @@ pub(crate) const SHORTCUT_BINDINGS: &[ShortcutBinding] = &[
shortcut(ShortcutAction::ToggleFavoriteTab, ShortcutPlatform::WindowsLinux, "ctrl-shift-f"),
shortcut(ShortcutAction::FocusCommandMode, ShortcutPlatform::Macos, "cmd-shift-p"),
shortcut(ShortcutAction::FocusCommandMode, ShortcutPlatform::WindowsLinux, "ctrl-shift-p"),
shortcut(ShortcutAction::SelectNextSpace, ShortcutPlatform::Macos, "cmd-alt-right"),
shortcut(ShortcutAction::SelectNextSpace, ShortcutPlatform::WindowsLinux, "ctrl-alt-right"),
shortcut(ShortcutAction::SelectPreviousSpace, ShortcutPlatform::Macos, "cmd-alt-left"),
shortcut(ShortcutAction::SelectPreviousSpace, ShortcutPlatform::WindowsLinux, "ctrl-alt-left"),
shortcut(ShortcutAction::SelectNextTab, ShortcutPlatform::Macos, "cmd-shift-]"),
shortcut(ShortcutAction::SelectNextTab, ShortcutPlatform::Macos, "cmd-alt-down"),
shortcut(ShortcutAction::SelectNextTab, ShortcutPlatform::WindowsLinux, "ctrl-tab"),
@@ -239,7 +253,13 @@ impl ShortcutBinding {
ShortcutAction::RestoreClosedTab => {
KeyBinding::new(self.keystroke, RestoreClosedTab, None)
}
ShortcutAction::SelectNextSpace => {
KeyBinding::new(self.keystroke, SelectNextSpace, None)
}
ShortcutAction::SelectNextTab => KeyBinding::new(self.keystroke, SelectNextTab, None),
ShortcutAction::SelectPreviousSpace => {
KeyBinding::new(self.keystroke, SelectPreviousSpace, None)
}
ShortcutAction::SelectPreviousTab => {
KeyBinding::new(self.keystroke, SelectPreviousTab, None)
}
@@ -310,6 +330,35 @@ mod tests {
assert_eq!(bindings, vec!["Cmd + B".to_string(), "Ctrl + B".to_string()]);
}
#[test]
fn space_switch_shortcuts_have_platform_bindings() {
let next_bindings =
bindings_for_action(ShortcutAction::SelectNextSpace, ShortcutPlatform::Macos)
.chain(bindings_for_action(
ShortcutAction::SelectNextSpace,
ShortcutPlatform::WindowsLinux,
))
.map(|binding| binding.display_keystroke())
.collect::<Vec<_>>();
let previous_bindings =
bindings_for_action(ShortcutAction::SelectPreviousSpace, ShortcutPlatform::Macos)
.chain(bindings_for_action(
ShortcutAction::SelectPreviousSpace,
ShortcutPlatform::WindowsLinux,
))
.map(|binding| binding.display_keystroke())
.collect::<Vec<_>>();
assert_eq!(
next_bindings,
vec!["Cmd + Option + RIGHT".to_string(), "Ctrl + Alt + RIGHT".to_string()]
);
assert_eq!(
previous_bindings,
vec!["Cmd + Option + LEFT".to_string(), "Ctrl + Alt + LEFT".to_string()]
);
}
#[test]
fn every_declared_action_has_a_binding() {
for action in SHORTCUT_ACTIONS {