mirror of
https://github.com/jlengrand/Maestro.git
synced 2026-03-10 08:31:19 +00:00
MAESTRO: Allow Cmd+T/W tab shortcuts from file preview
Tab management shortcuts (Cmd+T new tab, Cmd+W close tab) now work when viewing a file preview tab. Previously these shortcuts were blocked because file preview registers as an overlay in the layer stack. Added these to the allowlist of shortcuts that work when overlays (but not modals) are open.
This commit is contained in:
@@ -334,6 +334,50 @@ describe('useMainKeyboardHandler', () => {
|
||||
// Layout shortcuts should work even when modal is open
|
||||
expect(mockSetLeftSidebar).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should allow tab management shortcuts (Cmd+T) when only overlays are open', () => {
|
||||
const { result } = renderHook(() => useMainKeyboardHandler());
|
||||
|
||||
const mockSetSessions = vi.fn();
|
||||
const mockSetActiveFocus = vi.fn();
|
||||
const mockInputRef = { current: { focus: vi.fn() } };
|
||||
const mockActiveSession = {
|
||||
id: 'test-session',
|
||||
name: 'Test',
|
||||
aiTabs: [],
|
||||
activeTabId: 'tab-1',
|
||||
unifiedTabOrder: [],
|
||||
};
|
||||
|
||||
result.current.keyboardHandlerRef.current = createMockContext({
|
||||
hasOpenLayers: () => true, // Overlay is open (e.g., file preview)
|
||||
hasOpenModal: () => false, // But no true modal
|
||||
isTabShortcut: (_e: KeyboardEvent, actionId: string) => actionId === 'newTab',
|
||||
activeSession: mockActiveSession,
|
||||
createTab: vi.fn().mockReturnValue({
|
||||
session: { ...mockActiveSession, aiTabs: [{ id: 'new-tab' }] },
|
||||
}),
|
||||
setSessions: mockSetSessions,
|
||||
setActiveFocus: mockSetActiveFocus,
|
||||
inputRef: mockInputRef,
|
||||
defaultSaveToHistory: true,
|
||||
defaultShowThinking: 'on',
|
||||
});
|
||||
|
||||
act(() => {
|
||||
window.dispatchEvent(
|
||||
new KeyboardEvent('keydown', {
|
||||
key: 't',
|
||||
metaKey: true,
|
||||
bubbles: true,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Cmd+T should create a new tab even when file preview overlay is open
|
||||
expect(mockSetSessions).toHaveBeenCalled();
|
||||
expect(mockSetActiveFocus).toHaveBeenCalledWith('main');
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigation handlers delegation', () => {
|
||||
|
||||
@@ -114,6 +114,12 @@ export function useMainKeyboardHandler(): UseMainKeyboardHandlerReturn {
|
||||
// NOTE: Must use e.code for Alt key combos on macOS because e.key produces special characters
|
||||
const isSessionJumpShortcut =
|
||||
e.altKey && (e.metaKey || e.ctrlKey) && /^Digit[0-9]$/.test(e.code || '');
|
||||
// Allow tab management shortcuts (Cmd+T new tab, Cmd+W close tab) even when file preview overlay is open
|
||||
const isTabManagementShortcut =
|
||||
(e.metaKey || e.ctrlKey) &&
|
||||
!e.shiftKey &&
|
||||
!e.altKey &&
|
||||
(keyLower === 't' || keyLower === 'w');
|
||||
|
||||
if (ctx.hasOpenModal()) {
|
||||
// TRUE MODAL is open - block most shortcuts from App.tsx
|
||||
@@ -133,6 +139,7 @@ export function useMainKeyboardHandler(): UseMainKeyboardHandlerReturn {
|
||||
// Allow Cmd+Shift+[] to fall through to App.tsx handler
|
||||
// (which will cycle right panel tabs when file tab is active)
|
||||
// Also allow right panel tab shortcuts to switch tabs while overlay is open
|
||||
// Also allow tab management shortcuts (Cmd+T/W) so user can create/close tabs from file preview
|
||||
if (
|
||||
!isCycleShortcut &&
|
||||
!isLayoutShortcut &&
|
||||
@@ -140,7 +147,8 @@ export function useMainKeyboardHandler(): UseMainKeyboardHandlerReturn {
|
||||
!isSystemUtilShortcut &&
|
||||
!isSessionJumpShortcut &&
|
||||
!isJumpToBottomShortcut &&
|
||||
!isMarkdownToggleShortcut
|
||||
!isMarkdownToggleShortcut &&
|
||||
!isTabManagementShortcut
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user