From 3233a41215ec6929abe9ec1fcf81735fc78aea14 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 23 May 2026 15:54:47 -0700 Subject: [PATCH] Allow custom shortcut for equalizing panes Adds an unassigned terminal.equalizePaneSizes keybinding action so users can assign their own Equalize Pane Sizes shortcut without changing defaults. --- .../terminal-pane/TerminalContextMenu.tsx | 5 +++++ .../terminal-pane/keyboard-handlers.ts | 14 ++++++++++++++ .../terminal-shortcut-policy.test.ts | 16 ++++++++++++++++ .../terminal-pane/terminal-shortcut-policy.ts | 5 +++++ src/shared/keybindings.test.ts | 19 +++++++++++++++++++ src/shared/keybindings.ts | 9 +++++++++ 6 files changed, 68 insertions(+) diff --git a/src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx b/src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx index e404d459b21..ff9b3bf90e2 100644 --- a/src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx +++ b/src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx @@ -81,9 +81,11 @@ export default function TerminalContextMenu({ const pasteShortcut = useShortcutLabel('terminal.paste') const splitRightShortcut = useShortcutLabel('terminal.splitRight') const splitDownShortcut = useShortcutLabel('terminal.splitDown') + const equalizeShortcut = useShortcutLabel('terminal.equalizePaneSizes') const expandShortcut = useShortcutLabel('terminal.expandPane') const closeShortcut = useShortcutLabel('terminal.closePane') const hasQuickCommands = repoQuickCommands.length > 0 || globalQuickCommands.length > 0 + const showEqualizeShortcut = equalizeShortcut !== 'Unassigned' return ( Equalize Pane Sizes + {showEqualizeShortcut ? ( + {equalizeShortcut} + ) : null} )} {canExpandPane && ( diff --git a/src/renderer/src/components/terminal-pane/keyboard-handlers.ts b/src/renderer/src/components/terminal-pane/keyboard-handlers.ts index 41314c7740f..ac2a6650ba3 100644 --- a/src/renderer/src/components/terminal-pane/keyboard-handlers.ts +++ b/src/renderer/src/components/terminal-pane/keyboard-handlers.ts @@ -306,6 +306,20 @@ export function useTerminalKeyboardShortcuts({ return } + if (action.type === 'equalizePaneSizes') { + // Consume the chord first so a user-assigned terminal shortcut can't fall + // through to app-level zoom when an expanded pane blocks the equalize. + e.preventDefault() + e.stopImmediatePropagation() + if (expandedPaneIdRef.current !== null) { + return + } + manager.equalizePaneSizes() + const paneToFocus = manager.getActivePane() ?? manager.getPanes()[0] + paneToFocus?.terminal.focus() + return + } + // Cmd+Shift+Enter expands/collapses the active pane to full terminal area. if (action.type === 'toggleExpandActivePane') { const panes = manager.getPanes() diff --git a/src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts b/src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts index b78dd570bb0..fbb5dfa4a36 100644 --- a/src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts +++ b/src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts @@ -189,6 +189,22 @@ describe('resolveTerminalShortcutAction', () => { ).toBeNull() }) + it('resolves equalize pane sizes only when users assign it', () => { + expect( + resolveTerminalShortcutAction(event({ key: '=', code: 'Equal', metaKey: true }), true) + ).toBeNull() + expect( + resolveTerminalShortcutAction( + event({ key: '=', code: 'Equal', metaKey: true }), + true, + 'false', + 0, + false, + { 'terminal.equalizePaneSizes': ['Mod+Equal'] } + ) + ).toEqual({ type: 'equalizePaneSizes' }) + }) + it('lets Ctrl+D pass through as EOF on non-Mac, requires Shift for split (#586)', () => { // Ctrl+D without Shift on Windows/Linux must NOT trigger split — it's EOF expect( diff --git a/src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts b/src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts index 8c96e21e60e..5b648f2fabe 100644 --- a/src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts +++ b/src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts @@ -33,6 +33,7 @@ export type TerminalShortcutAction = | { type: 'toggleSearch' } | { type: 'clearActivePane' } | { type: 'focusPane'; direction: 'next' | 'previous' } + | { type: 'equalizePaneSizes' } | { type: 'toggleExpandActivePane' } | { type: 'closeActivePane' } | { type: 'splitActivePane'; direction: 'vertical' | 'horizontal' } @@ -68,6 +69,10 @@ export function resolveTerminalShortcutAction( return { type: 'focusPane', direction: 'next' } } + if (keybindingMatchesAction('terminal.equalizePaneSizes', event, platform, keybindings)) { + return { type: 'equalizePaneSizes' } + } + if (keybindingMatchesAction('terminal.expandPane', event, platform, keybindings)) { return { type: 'toggleExpandActivePane' } } diff --git a/src/shared/keybindings.test.ts b/src/shared/keybindings.test.ts index cf6ec9a4c26..0ea82b947cc 100644 --- a/src/shared/keybindings.test.ts +++ b/src/shared/keybindings.test.ts @@ -118,6 +118,25 @@ describe('keybindings', () => { }) }) + it('keeps equalize pane sizes unassigned until users customize it', () => { + expect(getEffectiveKeybindingsForAction('terminal.equalizePaneSizes', 'darwin')).toEqual([]) + expect( + keybindingMatchesAction( + 'terminal.equalizePaneSizes', + { key: '=', code: 'Equal', control: false, meta: true, alt: false, shift: false }, + 'darwin' + ) + ).toBe(false) + expect( + keybindingMatchesAction( + 'terminal.equalizePaneSizes', + { key: '=', code: 'Equal', control: false, meta: true, alt: false, shift: false }, + 'darwin', + { 'terminal.equalizePaneSizes': ['Mod+Equal'] } + ) + ).toBe(true) + }) + it('reports customized renderer conflicts with native menu accelerators', () => { expect(findKeybindingConflicts('darwin')).toEqual([]) diff --git a/src/shared/keybindings.ts b/src/shared/keybindings.ts index 5d5bff9bab7..240349bd64a 100644 --- a/src/shared/keybindings.ts +++ b/src/shared/keybindings.ts @@ -79,6 +79,7 @@ export type KeybindingActionId = | 'terminal.clear' | 'terminal.focusNextPane' | 'terminal.focusPreviousPane' + | 'terminal.equalizePaneSizes' | 'terminal.expandPane' | 'terminal.closePane' | 'terminal.splitRight' @@ -633,6 +634,14 @@ export const KEYBINDING_DEFINITIONS: readonly KeybindingDefinition[] = [ searchKeywords: ['shortcut', 'pane', 'focus', 'previous'], defaultBindings: platformBindings(['Mod+BracketLeft']) }, + { + id: 'terminal.equalizePaneSizes', + title: 'Equalize pane sizes', + group: 'Terminal Panes', + scope: 'terminal', + searchKeywords: ['shortcut', 'pane', 'split', 'equalize', 'resize', 'balance', 'size'], + defaultBindings: platformBindings([]) + }, { id: 'terminal.expandPane', title: 'Expand / collapse pane',