feat: add Cmd-B sidebar toggle shortcut (#1775)

Co-authored-by: Dr. Lukas Metzger <lukas@mba.lan>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-06 20:48:20 -06:00
1 parent 9778b6e56a
commit b912a31e00
5 files changed
+60 -6

No files matched your search

+1
View File
@@ -631,6 +631,7 @@ export const CORE_KEYBINDING_ACTIONS: readonly string[] = [
"previousTab",
"openCommandPalette",
"reconnectSession",
"toggleSidebar",
];
/**
+2 -1
View File
@@ -1054,7 +1054,8 @@
"actionNextTab": "Switch to next tab",
"actionPreviousTab": "Switch to previous tab",
"actionOpenCommandPalette": "Open quick search",
"actionReconnectSession": "Reconnect current session"
"actionReconnectSession": "Reconnect current session",
"actionToggleSidebar": "Toggle sidebar"
},
"userProfile": {
"preset_simple": "Simple",
@@ -8,7 +8,10 @@ import {
} from "@/lib/app-keyboard-shortcuts";
import { getUserPreferences } from "@/main-axios";
import { parseCustomKeybindings } from "@/api/open-tabs-api";
import { findMatchingKeybinding } from "@/lib/keybinding-match";
import {
eventMatchesCombo,
findMatchingKeybinding,
} from "@/lib/keybinding-match";
import type {
CustomKeybinding,
KeybindingActionType,
@@ -16,6 +19,7 @@ import type {
import {
GLOBAL_KEYBINDING_EVENT,
getKeybindingAction,
listKeybindingDefaults,
runKeybindingAction,
} from "@/shell/keybinding-registry";
import { globalShortcutHandler } from "@/lib/global-shortcut-handler";
@@ -53,7 +57,7 @@ export function useShellKeybindings({
if (cancelled) return;
globalKeybindingsRef.current = parseCustomKeybindings(
prefs.customKeybindings,
).filter((binding) => binding.enabled);
);
})
.catch(() => {});
};
@@ -78,6 +82,10 @@ export function useShellKeybindings({
(termRef?.current as TabHandle | null)?.reconnect?.();
return;
}
if (type === "toggleSidebar") {
regions.left.setOpen((open) => !open);
return;
}
const currentTabs = tabsRef.current.filter(
(tab) => !tab.parentSplitTabId,
);
@@ -97,16 +105,32 @@ export function useShellKeybindings({
)
return;
// Only actions that run anywhere; a terminal's own are its to handle.
const customBindings = globalKeybindingsRef.current;
const binding = findMatchingKeybinding(
event,
globalKeybindingsRef.current.filter(
(entry) => getKeybindingAction(entry.action.type)?.scope === "global",
customBindings.filter(
(entry) =>
entry.enabled &&
getKeybindingAction(entry.action.type)?.scope === "global",
),
);
if (!binding) return;
if (binding) {
event.preventDefault();
event.stopPropagation();
runKeybindingAction(binding.action);
return;
}
const defaultBinding = listKeybindingDefaults().find(
(entry) =>
!customBindings.some(
(custom) => custom.overridesDefaultId === entry.id,
) && eventMatchesCombo(event, entry.combo),
);
if (!defaultBinding || !getKeybindingAction(defaultBinding.id)) return;
event.preventDefault();
event.stopPropagation();
runKeybindingAction({ type: defaultBinding.id });
};
const handleAction = (event: Event) =>
runAction(
+20
View File
@@ -84,6 +84,11 @@ const SHELL_ACTIONS: KeybindingActionDef[] = [
"newUi.sidebar.keybindings.actionReconnectSession",
1003,
),
shellAction(
"toggleSidebar",
"newUi.sidebar.keybindings.actionToggleSidebar",
1004,
),
];
export const SHELL_KEYBINDING_ACTION_IDS = SHELL_ACTIONS.map(
@@ -97,6 +102,21 @@ function install(): void {
for (const action of SHELL_ACTIONS) {
if (!actions.get(action.id)) actions.register(action);
}
if (!defaults.get("toggleSidebar")) {
defaults.register({
id: "toggleSidebar",
combo: {
key: "KeyB",
isCode: true,
ctrl: false,
alt: false,
shift: false,
meta: true,
},
descriptionKey: "newUi.sidebar.keybindings.actionToggleSidebar",
order: 1004,
});
}
}
install();
@@ -4,6 +4,7 @@ import {
SHELL_KEYBINDING_ACTION_IDS,
getKeybindingAction,
listKeybindingActions,
listKeybindingDefaults,
registerKeybindingAction,
resetKeybindingRegistry,
runKeybindingAction,
@@ -17,6 +18,13 @@ describe("keybinding registry", () => {
SHELL_KEYBINDING_ACTION_IDS,
);
expect(getKeybindingAction("nextTab")?.scope).toBe("global");
expect(getKeybindingAction("toggleSidebar")?.scope).toBe("global");
expect(listKeybindingDefaults()).toEqual([
expect.objectContaining({
id: "toggleSidebar",
combo: expect.objectContaining({ key: "KeyB", meta: true }),
}),
]);
});
it("runs a shell action by telling the shell", () => {