Match Zellij tab and pane navigation shortcuts

This commit is contained in:
2026-11-17 01:32:41 -08:00
parent 79553a180e
commit 4655f8149b
5 changed files with 112 additions and 21 deletions
+97
View File
@@ -0,0 +1,97 @@
//! Application shortcuts, including the user's Zellij `locked`/`shared` map.
//! Registry commands remain available even when they have no shortcut here.
use gpui::Keystroke;
use crate::commands::CommandAction;
pub fn action_for_key(key: &Keystroke) -> Option<CommandAction> {
let modifiers = key.modifiers;
let name = key.key.to_lowercase();
if (modifiers.control || modifiers.platform) && modifiers.shift && !modifiers.alt {
return Some(match name.as_str() {
"t" => CommandAction::NewTab,
"d" => CommandAction::SplitPane,
"w" => CommandAction::ClosePane,
"r" => CommandAction::RenamePane,
"c" => CommandAction::Copy,
"v" => CommandAction::Paste,
"left" => CommandAction::PreviousPane,
"right" => CommandAction::NextPane,
_ => return None,
});
}
if !modifiers.alt || modifiers.control || modifiers.platform {
return None;
}
if modifiers.shift {
// Wayland keyboard layouts can report the shifted symbol for brackets.
Some(match name.as_str() {
"[" | "{" => CommandAction::PreviousTab,
"]" | "}" => CommandAction::NextTab,
"n" | "right" => CommandAction::NewTab,
_ => return None,
})
} else {
Some(match name.as_str() {
// GPUI consumes Shift for punctuation, leaving Alt+{ / Alt+}.
"{" => CommandAction::PreviousTab,
"}" => CommandAction::NextTab,
"left" => CommandAction::FocusLeft,
"right" => CommandAction::FocusRight,
"\\" => CommandAction::SplitPane,
_ => return None,
})
}
}
#[cfg(test)]
mod tests {
use super::*;
fn action(key: &str) -> Option<CommandAction> {
action_for_key(&Keystroke::parse(key).unwrap())
}
#[test]
fn zellij_tab_bindings_accept_shifted_and_unshifted_brackets() {
for key in ["alt-shift-[", "alt-shift-{", "alt-{"] {
assert!(matches!(action(key), Some(CommandAction::PreviousTab)));
}
for key in ["alt-shift-]", "alt-shift-}", "alt-}"] {
assert!(matches!(action(key), Some(CommandAction::NextTab)));
}
for key in ["alt-shift-n", "alt-shift-right"] {
assert!(matches!(action(key), Some(CommandAction::NewTab)));
}
}
#[test]
fn zellij_horizontal_focus_and_existing_shortcuts_coexist() {
assert!(matches!(action("alt-left"), Some(CommandAction::FocusLeft)));
assert!(matches!(
action("alt-right"),
Some(CommandAction::FocusRight)
));
assert!(matches!(action("alt-\\"), Some(CommandAction::SplitPane)));
assert!(matches!(
action("ctrl-shift-left"),
Some(CommandAction::PreviousPane)
));
assert!(matches!(action("cmd-shift-t"), Some(CommandAction::NewTab)));
}
#[test]
fn shell_keys_and_unconfigured_modes_remain_available() {
for key in [
"ctrl-c",
"ctrl-t",
"ctrl-p",
"alt-h",
"alt-ctrl-left",
"left",
"shift-right",
] {
assert!(action(key).is_none(), "{key} must reach the terminal");
}
}
}
+4 -4
View File
@@ -131,7 +131,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
"previous-tab",
"Previous tab",
"switch navigate left",
None,
Some("Alt+Shift+["),
PreviousTab,
)
.available(tabs),
@@ -139,7 +139,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
"next-tab",
"Next tab",
"switch navigate right",
None,
Some("Alt+Shift+]"),
NextTab,
)
.available(tabs),
@@ -163,7 +163,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
"focus-left",
"Focus pane or tab left",
"navigate previous horizontal",
None,
Some("Alt+Left"),
FocusLeft,
)
.available(pane),
@@ -171,7 +171,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
"focus-right",
"Focus pane or tab right",
"navigate next horizontal",
None,
Some("Alt+Right"),
FocusRight,
)
.available(pane),
+1
View File
@@ -1,3 +1,4 @@
mod bindings;
mod chrome;
mod client;
mod colors;
+1 -15
View File
@@ -116,21 +116,7 @@ impl Workspace {
{
return;
}
let action = if command {
match key.key.to_lowercase().as_str() {
"t" => Some(CommandAction::NewTab),
"d" => Some(CommandAction::SplitPane),
"w" => Some(CommandAction::ClosePane),
"r" => Some(CommandAction::RenamePane),
"c" => Some(CommandAction::Copy),
"v" => Some(CommandAction::Paste),
"left" => Some(CommandAction::PreviousPane),
"right" => Some(CommandAction::NextPane),
_ => None,
}
} else {
None
};
let action = crate::bindings::action_for_key(key);
if let Some(action) = action {
self.execute(action, window, cx);
cx.stop_propagation();