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
+9 -2
View File
@@ -108,7 +108,10 @@ run `psyterm --shutdown` on the remote host, for example through SSH.
| Ctrl/Cmd+Shift+P | Open the command palette | | Ctrl/Cmd+Shift+P | Open the command palette |
| Click a tab | Switch the server's active tab | | Click a tab | Switch the server's active tab |
| `+` or Ctrl+Shift+T | Create a tab | | `+` or Ctrl+Shift+T | Create a tab |
| Ctrl+Shift+D | Add a pane beside the focused pane | | Ctrl+Shift+D or Alt+\ | Add a pane beside the focused pane |
| Alt+Left / Right | Focus the adjacent pane, then adjacent tab at the edge |
| Alt+Shift+[ / ] | Switch to the previous / next tab |
| Alt+Shift+N or Alt+Shift+Right | Create a tab |
| Ctrl+Shift+Left / Right | Focus the previous / next pane | | Ctrl+Shift+Left / Right | Focus the previous / next pane |
| Ctrl+Shift+W | Close the focused pane and its shell | | Ctrl+Shift+W | Close the focused pane and its shell |
| Ctrl+Shift+R | Edit the pane name | | Ctrl+Shift+R | Edit the pane name |
@@ -121,6 +124,10 @@ run `psyterm --shutdown` on the remote host, for example through SSH.
| Shift+PageUp / PageDown | Scroll one page | | Shift+PageUp / PageDown | Scroll one page |
| Shift+Home / End | Jump to oldest history / live screen | | Shift+Home / End | Jump to oldest history / live screen |
Navigation follows the `shared` bindings in `~/.config/zellij/config.kdl`, with
Alt+\ from its default `locked` mode. Existing psyTerm shortcuts remain available;
Zellij's modal Ctrl bindings are left to terminal programs.
The command palette searches command names and keywords as you type. Arrow keys The command palette searches command names and keywords as you type. Arrow keys
or Tab select a result; Enter runs it or opens a submenu. Escape returns to the or Tab select a result; Enter runs it or opens a submenu. Escape returns to the
parent menu, then closes the palette. “Switch to tab…” and “Focus pane…” offer parent menu, then closes the palette. “Switch to tab…” and “Focus pane…” offer
@@ -182,7 +189,7 @@ scrollback by default.
| `protocol.rs`, `client.rs` | Versioned bounded messages, local socket / SSH transport, snapshot delivery | | `protocol.rs`, `client.rs` | Versioned bounded messages, local socket / SSH transport, snapshot delivery |
| `launcher.rs` | Server startup, private paths, lifecycle locks, and the server-owned GUI zygote | | `launcher.rs` | Server startup, private paths, lifecycle locks, and the server-owned GUI zygote |
| `terminal.rs` | Snapshot-only GUI workspace and panes, command dispatch, focus, and animation scheduling | | `terminal.rs` | Snapshot-only GUI workspace and panes, command dispatch, focus, and animation scheduling |
| `commands.rs`, `palette.rs` | Extensible command metadata, optional shortcuts, searchable nested menus | | `commands.rs`, `bindings.rs`, `palette.rs` | Extensible command metadata, optional shortcuts, searchable nested menus |
| `pane_name.rs`, `label.rs` | Pane name editor, Unicode composition, and middle-truncated labels | | `pane_name.rs`, `label.rs` | Pane name editor, Unicode composition, and middle-truncated labels |
| `render.rs`, `cursor.rs` | Cached text and batched drawing; cursor motion and blink | | `render.rs`, `cursor.rs` | Cached text and batched drawing; cursor motion and blink |
| `chrome.rs`, `colors.rs`, `fonts.rs` | Window chrome, terminal colors, font selection | | `chrome.rs`, `colors.rs`, `fonts.rs` | Window chrome, terminal colors, font selection |
+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",
"Previous tab", "Previous tab",
"switch navigate left", "switch navigate left",
None, Some("Alt+Shift+["),
PreviousTab, PreviousTab,
) )
.available(tabs), .available(tabs),
@@ -139,7 +139,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
"next-tab", "next-tab",
"Next tab", "Next tab",
"switch navigate right", "switch navigate right",
None, Some("Alt+Shift+]"),
NextTab, NextTab,
) )
.available(tabs), .available(tabs),
@@ -163,7 +163,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
"focus-left", "focus-left",
"Focus pane or tab left", "Focus pane or tab left",
"navigate previous horizontal", "navigate previous horizontal",
None, Some("Alt+Left"),
FocusLeft, FocusLeft,
) )
.available(pane), .available(pane),
@@ -171,7 +171,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
"focus-right", "focus-right",
"Focus pane or tab right", "Focus pane or tab right",
"navigate next horizontal", "navigate next horizontal",
None, Some("Alt+Right"),
FocusRight, FocusRight,
) )
.available(pane), .available(pane),
+1
View File
@@ -1,3 +1,4 @@
mod bindings;
mod chrome; mod chrome;
mod client; mod client;
mod colors; mod colors;
+1 -15
View File
@@ -116,21 +116,7 @@ impl Workspace {
{ {
return; return;
} }
let action = if command { let action = crate::bindings::action_for_key(key);
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
};
if let Some(action) = action { if let Some(action) = action {
self.execute(action, window, cx); self.execute(action, window, cx);
cx.stop_propagation(); cx.stop_propagation();