From 5db74fbb2dad376ece21080e6d7cb8ae219744f6 Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Thu, 20 Aug 2026 17:11:05 +0800 Subject: [PATCH] feat: add focus mode for split panes --- application/AppHandlers.globalHotkeys.test.ts | 86 +++++++- application/app/AppHandlers.ts | 40 +++- application/app/AppShell.architecture.test.ts | 2 + application/app/AppSideEffects.tsx | 13 +- application/app/AppView.tsx | 49 ++++- application/app/hosts/TerminalHost.tsx | 2 + application/i18n/locales/en/ai.ts | 4 + application/i18n/locales/es/ai.ts | 6 +- application/i18n/locales/ru/ai.ts | 4 + application/i18n/locales/zh-CN/ai.ts | 4 + application/i18n/locales/zh-TW/ai.ts | 4 + .../useTerminalSidePanelLayoutState.test.tsx | 14 ++ .../state/useTerminalSidePanelLayoutState.ts | 18 ++ ...QuickSwitcher.pluginContributions.test.tsx | 20 ++ components/QuickSwitcher.tsx | 63 ++++++ components/SftpView.memo.test.tsx | 25 +++ components/SftpView.tsx | 94 ++++++++- components/TerminalLayer.tsx | 84 ++++++++ .../TerminalLayerSidePanelSection.test.ts | 44 +++++ .../TerminalLayerSidePanelSection.tsx | 183 ++++++++++++++---- .../terminalLayer/TerminalLayerSupport.tsx | 3 +- .../terminalLayer/TerminalLayerTabBridge.tsx | 2 + components/terminalLayerMemo.ts | 1 + domain/sidePanelLayout.test.ts | 96 +++++++++ domain/sidePanelLayout.ts | 64 +++++- domain/workspaceSidePanelTabRemap.test.ts | 4 +- 26 files changed, 869 insertions(+), 60 deletions(-) diff --git a/application/AppHandlers.globalHotkeys.test.ts b/application/AppHandlers.globalHotkeys.test.ts index 8b5e1a8c1..d776a29ca 100644 --- a/application/AppHandlers.globalHotkeys.test.ts +++ b/application/AppHandlers.globalHotkeys.test.ts @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import test from 'node:test'; -import { executeHotkeyActionImpl, getLogHostVisualSnapshot, handleGlobalHotkeyKeyDownImpl } from './app/AppHandlers.ts'; +import { executeHotkeyActionImpl, getLogHostVisualSnapshot, handleEscapeKeyDownImpl, handleGlobalHotkeyKeyDownImpl } from './app/AppHandlers.ts'; import { matchesKeyBinding } from '../domain/models.ts'; import { DEFAULT_KEY_BINDINGS } from '../domain/models/keyBindings.ts'; @@ -170,6 +170,90 @@ test('quick switch hotkey toggles the quick switcher open state', () => { assert.equal(isQuickSwitcherOpen, false); }); +test('pane zoom hotkey prefers the active side panel split before workspace focus mode', () => { + let sidePanelToggles = 0; + let workspaceToggles = 0; + const workspace = { id: 'workspace-1' }; + const noop = () => {}; + + executeHotkeyActionImpl(() => ({ + IS_DEV: false, + MOVE_FOCUS_DEBOUNCE_MS: 0, + activeTabStore: { getActiveTabId: () => workspace.id }, + addConnectionLogRef: { current: noop }, + closeSession: noop, + closeTabInFlightRef: { current: false }, + closeWorkspace: noop, + collectSessionIds: () => [], + confirmIfBusyLocalTerminal: async () => true, + createLocalTerminalWithCurrentShell: noop, + editorTabs: [], + fromEditorTabId: () => null, + handleOpenSettingsRef: { current: noop }, + handleRequestCloseEditorTabRef: { current: noop }, + isEditorTabId: () => false, + isQuickSwitcherOpen: false, + lastMoveFocusTimeRef: { current: 0 }, + moveFocusInWorkspace: noop, + orderedTabs: [], + resolveCloseIntent: () => ({ kind: 'noop' }), + resolveSnippetsShortcutIntent: () => ({ kind: 'noop' }), + sessions: [], + setActiveTabId: noop, + setAddToWorkspaceDialog: noop, + setIsQuickSwitcherOpen: noop, + setNavigateToSection: noop, + settings: { showSftpTab: true, shellOnlyTabNumberShortcuts: false }, + sidePanelPaneZoomRef: { current: { + getState: () => 'focusable', + toggle: () => { sidePanelToggles += 1; return true; }, + } }, + splitSessionWithCurrentShell: noop, + systemInfoRef: { current: { username: 'user', hostname: 'host' } }, + toEditorTabId: (id: string) => `editor:${id}`, + toggleBroadcast: noop, + toggleScriptsSidePanelRef: { current: noop }, + toggleSidePanelRef: { current: noop }, + toggleWorkspaceViewMode: () => { workspaceToggles += 1; }, + workspaces: [workspace], + }), 'togglePaneZoom', { key: 'Enter' } as KeyboardEvent); + + assert.equal(sidePanelToggles, 1); + assert.equal(workspaceToggles, 0); +}); + +test('Escape exits side panel focus only after closing the command palette', () => { + let quickSwitcherClosed = 0; + let sidePanelRestores = 0; + const event = { + key: 'Escape', + preventDefault: noop, + stopPropagation: noop, + } as unknown as KeyboardEvent; + function noop() {} + + handleEscapeKeyDownImpl(() => ({ + isQuickSwitcherOpen: true, + setIsQuickSwitcherOpen: () => { quickSwitcherClosed += 1; }, + sidePanelPaneZoomRef: { current: { + getState: () => 'focused', + unfocus: () => { sidePanelRestores += 1; return true; }, + } }, + }), event); + assert.equal(quickSwitcherClosed, 1); + assert.equal(sidePanelRestores, 0); + + handleEscapeKeyDownImpl(() => ({ + isQuickSwitcherOpen: false, + setIsQuickSwitcherOpen: noop, + sidePanelPaneZoomRef: { current: { + getState: () => 'focused', + unfocus: () => { sidePanelRestores += 1; return true; }, + } }, + }), event); + assert.equal(sidePanelRestores, 1); +}); + test('close tab hotkey routes native plugin view tabs through their owner', () => { let closedTabId = ''; const pluginTabId = 'plugin-view:com.example.view:com.example.view.panel'; diff --git a/application/app/AppHandlers.ts b/application/app/AppHandlers.ts index 5cb62db8f..63459300f 100644 --- a/application/app/AppHandlers.ts +++ b/application/app/AppHandlers.ts @@ -1,9 +1,10 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import type React from 'react'; -import type { Host, HostProtocol, TerminalSession } from '../../types'; +import type { Host, HostProtocol, TerminalSession, Workspace } from '../../types'; import type { PassphraseRequest } from '../../components/PassphraseModal'; import type { TerminalPopupPayload } from '../../domain/systemManager/types'; import { getEffectiveHostDistro, classifyDistroId, shouldProbeSessionCwd } from '../../domain/host'; +import { getAvailablePaneZoomController } from '../../domain/sidePanelLayout'; import { sanitizeHostIconFields } from '../../domain/hostIcon'; import { resolveEffectiveTerminalProtocol } from '../../domain/terminalProtocol'; import { getTerminalPassthroughActions } from '../state/useGlobalHotkeys'; @@ -315,10 +316,35 @@ export function handleGlobalHotkeyKeyDownImpl(getCtx: AppContextGetter, e: Keybo } export function handleEscapeKeyDownImpl(getCtx: AppContextGetter, e: KeyboardEvent) { - const { isQuickSwitcherOpen, setIsQuickSwitcherOpen } = getCtx(); + const { + activeTabStore, + isQuickSwitcherOpen, + setIsQuickSwitcherOpen, + sidePanelPaneZoomRef, + sftpPaneZoomRef, + toggleWorkspaceViewMode, + workspaces, + } = getCtx(); { - if (e.key === 'Escape' && isQuickSwitcherOpen) { + if (e.key !== 'Escape') return; + if (isQuickSwitcherOpen) { setIsQuickSwitcherOpen(false); + return; + } + if (getAvailablePaneZoomController([ + sftpPaneZoomRef?.current, + sidePanelPaneZoomRef?.current, + ])?.unfocus()) { + e.preventDefault(); + e.stopPropagation(); + return; + } + const currentId = activeTabStore?.getActiveTabId(); + const activeWorkspace = workspaces?.find((workspace: Workspace) => workspace.id === currentId); + if (activeWorkspace?.viewMode === 'focus') { + toggleWorkspaceViewMode?.(activeWorkspace.id); + e.preventDefault(); + e.stopPropagation(); } } } @@ -671,7 +697,7 @@ export async function closeTabsBatchImpl(getCtx: AppContextGetter, targetIds: st } export function executeHotkeyActionImpl(getCtx: AppContextGetter, action: string, e: KeyboardEvent) { - const { IS_DEV, MOVE_FOCUS_DEBOUNCE_MS, activeTabStore, addConnectionLogRef, closePluginViewTab, closeSession, closeTabInFlightRef, closeWorkspace, collectSessionIds, confirmIfBusyLocalTerminal, createLocalTerminalWithCurrentShell, editorTabs, fromEditorTabId, handleOpenSettingsRef, handleRequestCloseEditorTabRef, isEditorTabId, isPluginViewTabId, isQuickSwitcherOpen, lastMoveFocusTimeRef, moveFocusInWorkspace, orderedTabs, resolveCloseIntent, resolveSnippetsShortcutIntent, sessions, setActiveTabId, setAddToWorkspaceDialog, setIsQuickSwitcherOpen, setNavigateToSection, settings, splitSessionWithCurrentShell, systemInfoRef, toEditorTabId, toggleBroadcast, toggleScriptsSidePanelRef, toggleSidePanelRef, toggleWorkspaceViewMode, workspaces } = getCtx(); + const { IS_DEV, MOVE_FOCUS_DEBOUNCE_MS, activeTabStore, addConnectionLogRef, closePluginViewTab, closeSession, closeTabInFlightRef, closeWorkspace, collectSessionIds, confirmIfBusyLocalTerminal, createLocalTerminalWithCurrentShell, editorTabs, fromEditorTabId, handleOpenSettingsRef, handleRequestCloseEditorTabRef, isEditorTabId, isPluginViewTabId, isQuickSwitcherOpen, lastMoveFocusTimeRef, moveFocusInWorkspace, orderedTabs, resolveCloseIntent, resolveSnippetsShortcutIntent, sessions, setActiveTabId, setAddToWorkspaceDialog, setIsQuickSwitcherOpen, setNavigateToSection, settings, sidePanelPaneZoomRef, sftpPaneZoomRef, splitSessionWithCurrentShell, systemInfoRef, toEditorTabId, toggleBroadcast, toggleScriptsSidePanelRef, toggleSidePanelRef, toggleWorkspaceViewMode, workspaces } = getCtx(); { const shortcutTabs = buildNumberShortcutTabTargets({ showSftpTab: settings.showSftpTab ?? true, @@ -907,7 +933,11 @@ export function executeHotkeyActionImpl(getCtx: AppContextGetter, action: string break; } case 'togglePaneZoom': { - // Toggle workspace between split and focus (zoom) mode + if (getAvailablePaneZoomController([ + sftpPaneZoomRef?.current, + sidePanelPaneZoomRef?.current, + ])?.toggle()) break; + // Fall back to the terminal workspace when no side-panel pane was active. const currentId = activeTabStore.getActiveTabId(); const activeWs = workspaces.find(w => w.id === currentId); if (activeWs) { diff --git a/application/app/AppShell.architecture.test.ts b/application/app/AppShell.architecture.test.ts index f293a1572..4dde9f465 100644 --- a/application/app/AppShell.architecture.test.ts +++ b/application/app/AppShell.architecture.test.ts @@ -125,6 +125,8 @@ test('TerminalHost builds from session snapshot + terminal settings store', () = assert.match(source, /useSessionSnapshot/); assert.match(source, /useSessionSnapshotActions|getSessionSnapshotActions/); assert.match(source, /useTerminalSettingsStore|getTerminalSettingsSnapshot/); + assert.match(source, /sidePanelPaneZoomRef:\s*handlers\.sidePanelPaneZoomRef/); + assert.match(source, /sftpPaneZoomRef:\s*handlers\.sftpPaneZoomRef/); assert.doesNotMatch(source, /\buseSessionState\s*\(/); assert.doesNotMatch(source, /\buseAppSessionRuntime\s*\(/); }); diff --git a/application/app/AppSideEffects.tsx b/application/app/AppSideEffects.tsx index 100434b33..0c11f71b2 100755 --- a/application/app/AppSideEffects.tsx +++ b/application/app/AppSideEffects.tsx @@ -52,6 +52,7 @@ import { } from '../../domain/terminalAppearance'; import { selectConnectionLogForTerminalDataCapture } from '../../domain/connectionLog'; import { collectSessionIds } from '../../domain/workspace'; +import type { SidePanelPaneZoomController } from '../../domain/sidePanelLayout'; import { resolveCloseIntent } from '../state/resolveCloseIntent'; import { resolveSnippetsShortcutIntent } from '../state/resolveSnippetsShortcutIntent'; import { resolveWindowCommandCloseIntent } from '../state/windowCommandClose'; @@ -580,6 +581,10 @@ export function AppSideEffects() { // Window controls - must be before update toast effect which uses openSettingsWindow const { openSettingsWindow } = useWindowControls(); + const toggleScriptsSidePanelRef = useRef<(() => void) | null>(null); + const toggleSidePanelRef = useRef<(() => void) | null>(null); + const sidePanelPaneZoomRef = useRef(null); + const sftpPaneZoomRef = useRef(null); const _handleTrayJumpToSession = useEffectEvent((sessionId: string) => { return handleTrayJumpToSessionImpl(() => ({ sessionId, @@ -596,7 +601,7 @@ export function AppSideEffects() { const _handleTrayPanelConnect = useEffectEvent((hostId: string) => { return handleTrayPanelConnectImpl(() => ({ addConnectionLog, connectToHost, hostId, hosts, identities, keys, resolveEffectiveHost, resolveHostAuth, systemInfoRef, t, toast }), hostId); }); const _handleTrayPanelConnectRequest = useEffectEvent((hostId: string) => { return handleTrayPanelConnectRequestImpl(() => ({ connectNow: _handleTrayPanelConnect, hostId, isVaultInitialized, queueConnect: (queuedHostId: string) => setPendingTrayPanelConnectHostIds((prev) => [...prev, queuedHostId]) }), hostId); }); const _handleGlobalHotkeyKeyDown = useEffectEvent((e: KeyboardEvent) => { return handleGlobalHotkeyKeyDownImpl(() => ({ HOTKEY_DEBUG, closeTabKeyStr, e, executeHotkeyAction, hotkeyScheme, keyBindings, matchesKeyBinding }), e); }); - const _handleEscapeKeyDown = useEffectEvent((e: KeyboardEvent) => { return handleEscapeKeyDownImpl(() => ({ e, isQuickSwitcherOpen, setIsQuickSwitcherOpen }), e); }); + const _handleEscapeKeyDown = useEffectEvent((e: KeyboardEvent) => { return handleEscapeKeyDownImpl(() => ({ activeTabStore, e, isQuickSwitcherOpen, setIsQuickSwitcherOpen, sidePanelPaneZoomRef, sftpPaneZoomRef, toggleWorkspaceViewMode, workspaces }), e); }); // Vault hosts for tray / auto-start; terminalHosts (vault + ephemeral) only for // dedicated transfer resume so quick-connect rows do not break tray connect. @@ -921,8 +926,6 @@ export function AppSideEffects() { isQuickSwitcherOpenRef.current = isQuickSwitcherOpen; const orderedTabsRef = useRef([]); - const toggleScriptsSidePanelRef = useRef<(() => void) | null>(null); - const toggleSidePanelRef = useRef<(() => void) | null>(null); const openNoteRequestIdRef = useRef(0); const [openNoteRequest, setOpenNoteRequest] = useState<{ tabId: string; @@ -1071,6 +1074,8 @@ export function AppSideEffects() { toggleBroadcast, toggleScriptsSidePanelRef, toggleSidePanelRef, + sidePanelPaneZoomRef, + sftpPaneZoomRef, toggleWorkspaceViewMode, workspaces: workspacesRefForHotkeys.current, }), action, e); @@ -1853,6 +1858,8 @@ export function AppSideEffects() { splitSessionWithCurrentShell, toggleScriptsSidePanelRef, toggleSidePanelRef, + sidePanelPaneZoomRef, + sftpPaneZoomRef, // Chrome glue handleEndSessionDrag, handleOpenQuickSwitcher, diff --git a/application/app/AppView.tsx b/application/app/AppView.tsx index 373d8b683..12b82f3ef 100644 --- a/application/app/AppView.tsx +++ b/application/app/AppView.tsx @@ -36,6 +36,8 @@ import { useExternalMcpToggleState } from '../state/useExternalMcpToggleState'; import { selectPluginThemeTokens } from '../state/pluginContributionEnvironment'; import { netcattyBridge } from '../../infrastructure/services/netcattyBridge'; import { resolveEffectiveTerminalHost } from '../../domain/terminalHostResolution'; +import { collectSessionIds } from '../../domain/workspace'; +import { getAvailablePaneZoomController } from '../../domain/sidePanelLayout'; import { pluginViewTabStore, usePluginViewTabs } from '../state/pluginViewTabStore'; import { buildPluginSettingScopeCatalog } from '../state/usePluginSettingScopeCatalog'; import { useWorkSurfaceHostEditor } from '../state/useWorkSurfaceHostEditor'; @@ -276,7 +278,7 @@ function AppViewInner({ domains }: AppViewProps) { setWorkspaceFocusedSession, sftpAutoOpenSidebar, sftpFollowTerminalCwd, setSftpFollowTerminalCwd, sftpAutoSync, sftpDefaultViewMode, sftpDoubleClickBehavior, sftpShowHiddenFiles, sftpUseCompressedUpload, snippetPackages, snippets, splitSessionWithCurrentShell, startSessionRename, startWorkspaceRename, submitSessionRename, submitWorkspaceRename, t, terminalFontFamilyId, terminalFontSize, terminalSettings, terminalThemeId, themeById, - toggleBroadcast, toggleScriptsSidePanelRef, toggleSidePanelRef, toggleWorkspaceViewMode, unmanageSource, + toggleBroadcast, toggleScriptsSidePanelRef, toggleSidePanelRef, sidePanelPaneZoomRef, sftpPaneZoomRef, toggleWorkspaceViewMode, unmanageSource, readPersistedHosts, readPersistedManagedSources, updateCustomGroups, updateGroupConfigs, updateHostDistro, updateHosts, updateIdentities, updateKeys, updateKnownHosts, updateManagedSources, updateProxyProfiles, updateSnippetPackages, updateSnippets, updateSplitSizes, updateTerminalSetting, vaultFocusRequest, workspaceRenameTarget, workspaces, VaultViewContainer, SftpViewMount, TerminalLayerMount, LogViewWrapper, @@ -465,6 +467,46 @@ function AppViewInner({ domains }: AppViewProps) { void netcattyBridge.get()?.setPluginScopeCatalog?.(catalog).catch(() => {}); }, [hosts, sessions, t, workspaces]); + const activePaneZoomWorkspace = workspaces.find( + (workspace) => workspace.id === activeTabStore.getActiveTabId(), + ); + const activePaneZoomController = getAvailablePaneZoomController([ + sftpPaneZoomRef?.current, + sidePanelPaneZoomRef?.current, + ]); + const sidePanelPaneZoomState = activePaneZoomController?.getState() ?? 'unavailable'; + const paneZoomState = sidePanelPaneZoomState !== 'unavailable' + ? sidePanelPaneZoomState + : activePaneZoomWorkspace && collectSessionIds(activePaneZoomWorkspace.root).length > 1 + ? (activePaneZoomWorkspace.viewMode === 'focus' ? 'focused' : 'focusable') + : 'unavailable'; + const handleFocusCurrentPane = () => { + if (getAvailablePaneZoomController([ + sftpPaneZoomRef?.current, + sidePanelPaneZoomRef?.current, + ])?.focus()) return; + const workspace = workspaces.find( + (entry) => entry.id === activeTabStore.getActiveTabId(), + ); + if ( + workspace + && workspace.viewMode !== 'focus' + && collectSessionIds(workspace.root).length > 1 + ) { + toggleWorkspaceViewMode(workspace.id); + } + }; + const handleUnfocusPane = () => { + if (getAvailablePaneZoomController([ + sftpPaneZoomRef?.current, + sidePanelPaneZoomRef?.current, + ])?.unfocus()) return; + const workspace = workspaces.find( + (entry) => entry.id === activeTabStore.getActiveTabId(), + ); + if (workspace?.viewMode === 'focus') toggleWorkspaceViewMode(workspace.id); + }; + return ( @@ -644,6 +686,7 @@ function AppViewInner({ domains }: AppViewProps) { editorWordWrap={editorWordWrap} setEditorWordWrap={setEditorWordWrap} terminalSettings={terminalSettings} + paneZoomRef={sftpPaneZoomRef} /> diff --git a/application/app/hosts/TerminalHost.tsx b/application/app/hosts/TerminalHost.tsx index 683ff5ec5..1703ad9ee 100644 --- a/application/app/hosts/TerminalHost.tsx +++ b/application/app/hosts/TerminalHost.tsx @@ -239,6 +239,8 @@ export function TerminalHost() { toggleBroadcast: sessionActions?.toggleBroadcast, toggleScriptsSidePanelRef: handlers.toggleScriptsSidePanelRef, toggleSidePanelRef: handlers.toggleSidePanelRef, + sidePanelPaneZoomRef: handlers.sidePanelPaneZoomRef, + sftpPaneZoomRef: handlers.sftpPaneZoomRef, toggleWorkspaceViewMode: sessionActions?.toggleWorkspaceViewMode, updateHostDistro: vaultActions?.updateHostDistro, updateSplitSizes: sessionActions?.updateSplitSizes, diff --git a/application/i18n/locales/en/ai.ts b/application/i18n/locales/en/ai.ts index d1a45be8d..0e14accf7 100644 --- a/application/i18n/locales/en/ai.ts +++ b/application/i18n/locales/en/ai.ts @@ -569,6 +569,10 @@ export const enAiMessages: Messages = { 'terminal.layer.closePanel': 'Close panel', 'terminal.layer.closePane': 'Close split', 'terminal.layer.resizeSplit': 'Resize split', + 'terminal.layer.focusPane': 'Focus current pane', + 'terminal.layer.restorePanes': 'Restore split layout', + 'terminal.layer.unfocusPane': 'Unfocus pane', + 'terminal.layer.focusedPane': 'Focused', 'terminal.layer.splitHorizontal': 'Split top and bottom', 'terminal.layer.splitVertical': 'Split left and right', 'terminal.layer.openInNewSplit': 'Open in new split', diff --git a/application/i18n/locales/es/ai.ts b/application/i18n/locales/es/ai.ts index 4303054b1..cd792bb13 100644 --- a/application/i18n/locales/es/ai.ts +++ b/application/i18n/locales/es/ai.ts @@ -569,6 +569,10 @@ export const esAiMessages: Messages = { 'terminal.layer.closePanel': 'Cerrar panel', 'terminal.layer.closePane': 'Cerrar división', 'terminal.layer.resizeSplit': 'Redimensionar división', + 'terminal.layer.focusPane': 'Enfocar panel actual', + 'terminal.layer.restorePanes': 'Restaurar vista dividida', + 'terminal.layer.unfocusPane': 'Salir del enfoque', + 'terminal.layer.focusedPane': 'Enfocado', 'terminal.layer.splitHorizontal': 'Dividir arriba y abajo', 'terminal.layer.splitVertical': 'Dividir izquierda y derecha', 'terminal.layer.openInNewSplit': 'Abrir en una división nueva', @@ -653,4 +657,4 @@ export const esAiMessages: Messages = { 'zmodem.overwrite.skip': 'Omitir', 'zmodem.overwrite.cancel': 'Cancelar', 'settings.shortcuts.resetToDefault': 'Restablecer al predeterminado', -}; \ No newline at end of file +}; diff --git a/application/i18n/locales/ru/ai.ts b/application/i18n/locales/ru/ai.ts index 3cc087f59..76367483a 100644 --- a/application/i18n/locales/ru/ai.ts +++ b/application/i18n/locales/ru/ai.ts @@ -521,6 +521,10 @@ export const ruAiMessages: Messages = { 'terminal.layer.closePanel': 'Закрыть панель', 'terminal.layer.closePane': 'Закрыть область', 'terminal.layer.resizeSplit': 'Изменить размер области', + 'terminal.layer.focusPane': 'Развернуть текущую область', + 'terminal.layer.restorePanes': 'Восстановить разделение', + 'terminal.layer.unfocusPane': 'Выйти из фокуса', + 'terminal.layer.focusedPane': 'В фокусе', 'terminal.layer.splitHorizontal': 'Разделить сверху и снизу', 'terminal.layer.splitVertical': 'Разделить слева и справа', 'terminal.layer.openInNewSplit': 'Открыть в новой области', diff --git a/application/i18n/locales/zh-CN/ai.ts b/application/i18n/locales/zh-CN/ai.ts index 4cbcff38d..1bb918afd 100644 --- a/application/i18n/locales/zh-CN/ai.ts +++ b/application/i18n/locales/zh-CN/ai.ts @@ -569,6 +569,10 @@ export const zhCNAiMessages: Messages = { 'terminal.layer.closePanel': '关闭面板', 'terminal.layer.closePane': '关闭分屏', 'terminal.layer.resizeSplit': '调整分屏大小', + 'terminal.layer.focusPane': '放大当前面板', + 'terminal.layer.restorePanes': '还原分屏布局', + 'terminal.layer.unfocusPane': '退出聚焦', + 'terminal.layer.focusedPane': '已聚焦', 'terminal.layer.splitHorizontal': '上下分屏', 'terminal.layer.splitVertical': '左右分屏', 'terminal.layer.openInNewSplit': '在新分屏中打开', diff --git a/application/i18n/locales/zh-TW/ai.ts b/application/i18n/locales/zh-TW/ai.ts index f8692c4fc..f68893318 100644 --- a/application/i18n/locales/zh-TW/ai.ts +++ b/application/i18n/locales/zh-TW/ai.ts @@ -568,6 +568,10 @@ export const zhTWAiMessages: Messages = { 'terminal.layer.closePanel': '關閉面板', 'terminal.layer.closePane': '關閉分割', 'terminal.layer.resizeSplit': '調整分割大小', + 'terminal.layer.focusPane': '放大目前面板', + 'terminal.layer.restorePanes': '還原分割配置', + 'terminal.layer.unfocusPane': '退出聚焦', + 'terminal.layer.focusedPane': '已聚焦', 'terminal.layer.splitHorizontal': '上下分割', 'terminal.layer.splitVertical': '左右分割', 'terminal.layer.openInNewSplit': '在新分割中開啟', diff --git a/application/state/useTerminalSidePanelLayoutState.test.tsx b/application/state/useTerminalSidePanelLayoutState.test.tsx index 740fc7dd7..bd0e2dbeb 100644 --- a/application/state/useTerminalSidePanelLayoutState.test.tsx +++ b/application/state/useTerminalSidePanelLayoutState.test.tsx @@ -51,6 +51,20 @@ test('terminal side panel layouts stay isolated and keep one pane per tool', asy ['scripts'], ); + const splitRoot = state!.sidePanelLayouts.get('terminal-a')!.root; + await act(async () => { + state?.maximizePane('terminal-a', 'pane-ai'); + }); + assert.equal(state!.sidePanelLayouts.get('terminal-a')!.maximizedPaneId, 'pane-ai'); + assert.equal(state!.sidePanelLayouts.get('terminal-a')!.root, splitRoot); + assert.equal(state!.sidePanelLayouts.get('terminal-b')!.maximizedPaneId, null); + + await act(async () => { + state?.restoreLayout('terminal-a'); + }); + assert.equal(state!.sidePanelLayouts.get('terminal-a')!.maximizedPaneId, null); + assert.equal(state!.sidePanelLayouts.get('terminal-a')!.root, splitRoot); + await act(async () => { state?.splitPane('terminal-a', 'notes', 'horizontal', { paneId: 'unused-pane', diff --git a/application/state/useTerminalSidePanelLayoutState.ts b/application/state/useTerminalSidePanelLayoutState.ts index 3c62500fd..d2b3e9305 100644 --- a/application/state/useTerminalSidePanelLayoutState.ts +++ b/application/state/useTerminalSidePanelLayoutState.ts @@ -5,7 +5,9 @@ import { createSidePanelLayout, focusSidePanelPane, getFocusedSidePanelPane, + maximizeSidePanelPane, resizeSidePanelSplit, + restoreSidePanelLayout, selectSidePanelTool, splitSidePanelPane, type SidePanelLayout, @@ -118,6 +120,20 @@ export function useTerminalSidePanelLayoutState() { setSidePanelLayouts(layouts); }, []); + const maximizePane = useCallback((tabId: string, paneId: string) => { + const layout = sidePanelLayoutsRef.current.get(tabId); + if (!layout) return; + const nextLayout = maximizeSidePanelPane(layout, paneId); + if (nextLayout !== layout) commitLayout(tabId, nextLayout); + }, [commitLayout]); + + const restoreLayout = useCallback((tabId: string) => { + const layout = sidePanelLayoutsRef.current.get(tabId); + if (!layout) return; + const nextLayout = restoreSidePanelLayout(layout); + if (nextLayout !== layout) commitLayout(tabId, nextLayout); + }, [commitLayout]); + return { sidePanelOpenTabs, setSidePanelOpenTabs, @@ -129,5 +145,7 @@ export function useTerminalSidePanelLayoutState() { splitPane, closePane, resizeSplit, + maximizePane, + restoreLayout, }; } diff --git a/components/QuickSwitcher.pluginContributions.test.tsx b/components/QuickSwitcher.pluginContributions.test.tsx index 3d35b5933..a5939cc43 100644 --- a/components/QuickSwitcher.pluginContributions.test.tsx +++ b/components/QuickSwitcher.pluginContributions.test.tsx @@ -5,9 +5,29 @@ import test from 'node:test'; import { buildPluginPaletteItems, getQuickSwitcherRowStateClass, + buildPaneZoomPaletteAction, shouldUseQuickSwitcherPointerNavigation, } from './QuickSwitcher'; +test('command palette exposes the matching focus or restore action', () => { + const t = (key: string) => ({ + 'terminal.layer.focusPane': 'Focus current pane', + 'terminal.layer.unfocusPane': 'Unfocus pane', + }[key] ?? key); + + assert.deepEqual(buildPaneZoomPaletteAction('focusable', t), { + type: 'action', + id: 'focus-current-pane', + title: 'Focus current pane', + }); + assert.deepEqual(buildPaneZoomPaletteAction('focused', t), { + type: 'action', + id: 'unfocus-pane', + title: 'Unfocus pane', + }); + assert.equal(buildPaneZoomPaletteAction('unavailable', t), null); +}); + test('keeps the new workspace action outside the scrollable results', () => { const source = readFileSync(new URL('./QuickSwitcher.tsx', import.meta.url), 'utf8'); const actionIndex = source.indexOf('{/* Jump To hint + New Workspace action */}'); diff --git a/components/QuickSwitcher.tsx b/components/QuickSwitcher.tsx index 913b03dd0..3ab25178a 100644 --- a/components/QuickSwitcher.tsx +++ b/components/QuickSwitcher.tsx @@ -2,6 +2,8 @@ import { Folder, FolderLock, LayoutGrid, + Maximize2, + Minimize2, Plus, Search, Terminal, @@ -11,6 +13,7 @@ import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from " import { useI18n } from "../application/i18n/I18nProvider"; import { Host, TerminalSession, TerminalSettings, Workspace } from "../types"; import { KeyBinding } from "../domain/models"; +import type { SidePanelPaneZoomState } from "../domain/sidePanelLayout"; import { matchesSearchQuery } from "../lib/searchMatcher"; import { buildQuickSwitcherShells, useDiscoveredShells, getShellIconPath, isMonochromeShellIcon } from "../lib/useDiscoveredShells"; import { usePluginContributions } from "../application/state/usePluginContributions"; @@ -34,6 +37,19 @@ type QuickSwitcherItem = QuickSwitcherItemBase & ( | { type: "host" | "tab" | "workspace" | "action" | "shell" | "plugin-view"; commandId?: never } ); +export function buildPaneZoomPaletteAction( + state: SidePanelPaneZoomState, + t: (key: string) => string, +): QuickSwitcherItem | null { + if (state === 'focusable') { + return { type: 'action', id: 'focus-current-pane', title: t('terminal.layer.focusPane') }; + } + if (state === 'focused') { + return { type: 'action', id: 'unfocus-pane', title: t('terminal.layer.unfocusPane') }; + } + return null; +} + export function getQuickSwitcherRowStateClass( isSelected: boolean, isKeyboardNavigating: boolean, @@ -146,6 +162,9 @@ interface QuickSwitcherProps { keyBindings?: KeyBinding[]; showSftpTab: boolean; terminalSettings?: Pick; + paneZoomState?: SidePanelPaneZoomState; + onFocusCurrentPane?: () => void; + onUnfocusPane?: () => void; } const QuickSwitcherInner: React.FC = ({ @@ -164,6 +183,9 @@ const QuickSwitcherInner: React.FC = ({ keyBindings, showSftpTab, terminalSettings, + paneZoomState = 'unavailable', + onFocusCurrentPane, + onUnfocusPane, }) => { const { t } = useI18n(); const discoveredShells = useDiscoveredShells(); @@ -287,6 +309,10 @@ const QuickSwitcherInner: React.FC = ({ pluginContributions.snapshot.plugins, trimmedQuery, ), [pluginContributions.snapshot.plugins, trimmedQuery]); + const paneZoomPaletteAction = useMemo( + () => buildPaneZoomPaletteAction(paneZoomState, t), + [paneZoomState, t], + ); // Memoize flat selectable items + visual rows (headers + items) for virtualization. const { flatItems, visualRows, itemIndexToVisualIndex } = useMemo(() => { @@ -343,6 +369,14 @@ const QuickSwitcherInner: React.FC = ({ pushItem({ type: "action", id: "local-terminal" }); } + if (paneZoomPaletteAction && ( + !trimmedQuery + || matchesSearchQuery(trimmedQuery, paneZoomPaletteAction.title ?? '', 'pane', 'focus', 'zoom') + )) { + pushHeader("header:actions", t("settings.shortcuts.category.navigation")); + pushItem(paneZoomPaletteAction); + } + if (pluginPaletteItems.length > 0) { pushHeader("header:plugins", t("settings.tab.plugins")); pluginPaletteItems.forEach((item) => pushItem(item)); @@ -359,9 +393,11 @@ const QuickSwitcherInner: React.FC = ({ filteredShells, filteredWorkspaces, pluginPaletteItems, + paneZoomPaletteAction, results, shouldShowLocalTerminalFallback, t, + trimmedQuery, ]); useEffect(() => { @@ -421,6 +457,12 @@ const QuickSwitcherInner: React.FC = ({ if (item.id === "local-terminal" && onCreateLocalTerminal) { onCreateLocalTerminal(); onClose(); + } else if (item.id === 'focus-current-pane' && onFocusCurrentPane) { + onFocusCurrentPane(); + onClose(); + } else if (item.id === 'unfocus-pane' && onUnfocusPane) { + onUnfocusPane(); + onClose(); } break; case "shell": { @@ -679,6 +721,27 @@ const QuickSwitcherInner: React.FC = ({ ); } + if (item.type === 'action' && ( + item.id === 'focus-current-pane' || item.id === 'unfocus-pane' + )) { + const isRestore = item.id === 'unfocus-pane'; + return ( + + ); + } + if (item.type === "plugin-command" || item.type === "plugin-view") { return ( + )}
handlePaneFocus("left")} > {/* Focus indicator triangle */} @@ -544,7 +624,12 @@ const SftpViewInner: React.FC = ({
handlePaneFocus("right")} > {/* Focus indicator triangle */} @@ -669,6 +754,7 @@ export const sftpViewAreEqual = (prev: SftpViewProps, next: SftpViewProps): bool prev.sftpUseCompressedUpload === next.sftpUseCompressedUpload && prev.hotkeyScheme === next.hotkeyScheme && prev.keyBindings === next.keyBindings && + prev.paneZoomRef === next.paneZoomRef && prev.editorWordWrap === next.editorWordWrap && prev.setEditorWordWrap === next.setEditorWordWrap && // Only these terminal connection settings affect SFTP connection diff --git a/components/TerminalLayer.tsx b/components/TerminalLayer.tsx index 7191b5041..a096498d5 100644 --- a/components/TerminalLayer.tsx +++ b/components/TerminalLayer.tsx @@ -257,6 +257,7 @@ const TerminalLayerInner: React.FC = ({ showHostTreeSidebar = true, toggleScriptsSidePanelRef, toggleSidePanelRef, + sidePanelPaneZoomRef, // Session rename props onStartSessionRename, onSubmitSessionRename, @@ -276,6 +277,8 @@ const TerminalLayerInner: React.FC = ({ splitPane: splitSidePanelPaneForTab, closePane: closeSidePanelPaneForTab, resizeSplit: resizeSidePanelSplitForTab, + maximizePane: maximizeSidePanelPaneForTab, + restoreLayout: restoreSidePanelLayoutForTab, } = useTerminalSidePanelLayoutState(); const terminalRendererCwdBySessionRef = useRef>(new Map()); const stableRef = useRef>({}); @@ -283,6 +286,7 @@ const TerminalLayerInner: React.FC = ({ const activeWorkspaceRef = useRef(undefined); const activeSessionRef = useRef(undefined); const focusedSessionIdRef = useRef(undefined); + const lastInteractedSidePanelPaneRef = useRef>(new Map()); const terminalOsc7SignalBySessionRef = useRef>(new Map()); const cwdProbeCancelersRef = useRef void>>(new Map()); const cwdProbeGenerationRef = useRef>(new Map()); @@ -1394,9 +1398,86 @@ const TerminalLayerInner: React.FC = ({ const handleFocusSidePanelPane = useCallback((paneId: string) => { const tabId = activeTabIdRef.current; if (!tabId) return; + lastInteractedSidePanelPaneRef.current.set(tabId, paneId); focusSidePanelPaneForTab(tabId, paneId); }, [focusSidePanelPaneForTab]); + useEffect(() => { + const clearWhenTerminalPaneTakesFocus = (event: Event) => { + const target = event.target; + if (!(target instanceof Element)) return; + if (!target.closest('[data-section="terminal-split-pane"]')) return; + const tabId = activeTabIdRef.current; + if (tabId) lastInteractedSidePanelPaneRef.current.delete(tabId); + }; + document.addEventListener('pointerdown', clearWhenTerminalPaneTakesFocus, true); + document.addEventListener('focusin', clearWhenTerminalPaneTakesFocus, true); + return () => { + document.removeEventListener('pointerdown', clearWhenTerminalPaneTakesFocus, true); + document.removeEventListener('focusin', clearWhenTerminalPaneTakesFocus, true); + }; + }, []); + + const handleMaximizeSidePanelPane = useCallback((paneId: string) => { + const tabId = activeTabIdRef.current; + if (!tabId) return; + lastInteractedSidePanelPaneRef.current.set(tabId, paneId); + maximizeSidePanelPaneForTab(tabId, paneId); + }, [maximizeSidePanelPaneForTab]); + + const handleRestoreSidePanelLayout = useCallback(() => { + const tabId = activeTabIdRef.current; + if (!tabId) return; + restoreSidePanelLayoutForTab(tabId); + }, [restoreSidePanelLayoutForTab]); + + useEffect(() => { + if (!sidePanelPaneZoomRef) return; + const getTarget = () => { + const tabId = activeTabIdRef.current; + if (!tabId) return null; + const layout = sidePanelLayoutsRef.current.get(tabId); + if (!layout) return null; + if (layout.maximizedPaneId) { + return { tabId, layout, paneId: layout.maximizedPaneId, state: 'focused' as const }; + } + const paneId = lastInteractedSidePanelPaneRef.current.get(tabId); + if (!paneId) return null; + if (!collectSidePanelPanes(layout.root).some((pane) => pane.id === paneId)) return null; + return { tabId, layout, paneId, state: 'focusable' as const }; + }; + sidePanelPaneZoomRef.current = { + getState: () => getTarget()?.state ?? 'unavailable', + focus: () => { + const target = getTarget(); + if (!target || target.state === 'focused') return false; + maximizeSidePanelPaneForTab(target.tabId, target.paneId); + return true; + }, + unfocus: () => { + const target = getTarget(); + if (!target || target.state !== 'focused') return false; + restoreSidePanelLayoutForTab(target.tabId); + return true; + }, + toggle: () => { + const target = getTarget(); + if (!target) return false; + if (target.state === 'focused') restoreSidePanelLayoutForTab(target.tabId); + else maximizeSidePanelPaneForTab(target.tabId, target.paneId); + return true; + }, + }; + return () => { + sidePanelPaneZoomRef.current = null; + }; + }, [ + maximizeSidePanelPaneForTab, + restoreSidePanelLayoutForTab, + sidePanelLayoutsRef, + sidePanelPaneZoomRef, + ]); + const handleSplitSidePanelPane = useCallback(( tool: SidePanelTab, direction: SidePanelSplitDirection, @@ -2037,6 +2118,8 @@ const TerminalLayerInner: React.FC = ({ handleOpenSystem, handleOpenNotes, handleFocusSidePanelPane, + handleMaximizeSidePanelPane, + handleRestoreSidePanelLayout, handleSplitSidePanelPane, handleCloseSidePanelPane, handleResizeSidePanelSplit, @@ -2203,6 +2286,7 @@ const TerminalLayerInner: React.FC = ({ ThemeSidePanel, toggleScriptsSidePanelRef, toggleSidePanelRef, + sidePanelPaneZoomRef, Tooltip, TooltipContent, TooltipTrigger, diff --git a/components/terminalLayer/TerminalLayerSidePanelSection.test.ts b/components/terminalLayer/TerminalLayerSidePanelSection.test.ts index 32ea740ad..4b531ea4d 100644 --- a/components/terminalLayer/TerminalLayerSidePanelSection.test.ts +++ b/components/terminalLayer/TerminalLayerSidePanelSection.test.ts @@ -10,8 +10,10 @@ import { } from '../../application/state/terminalSidePanelTabs.ts'; import { getTerminalSidePanelShellWidth, + getSidePanelSplitChildPresentation, listenForSidePanelPaneFocus, } from './TerminalLayerSidePanelSection.tsx'; +import { createSidePanelLayout, splitSidePanelPane } from '../../domain/sidePanelLayout.ts'; import { resolveSidePanelPortalTarget } from './terminalLayerSidePanelSlots.tsx'; test('AI side panel shell can be force-hidden for layout isolation', () => { @@ -44,6 +46,18 @@ test('resize preview width is still honored for visible side panels', () => { }), 512); }); +test('a focused side-panel pane takes the full terminal work surface', () => { + assert.equal(getTerminalSidePanelShellWidth({ + activeSidePanelTab: 'sftp', + availableSurfaceWidth: 1180, + forceHideAiShell: false, + isSidePanelOpenForCurrentTab: true, + maximizedPaneId: 'pane-1', + resizePreviewWidth: null, + sidePanelWidth: 420, + }), 1180); +}); + test('closed side panel shell has no width', () => { assert.equal(getTerminalSidePanelShellWidth({ activeSidePanelTab: null, @@ -72,6 +86,29 @@ test('pointer and keyboard focus from portaled tool content focus the owning pan assert.equal(focusCount, 2); }); +test('maximized side panel rendering collapses siblings without replacing the layout tree', () => { + let layout = createSidePanelLayout('notes', 'pane-notes'); + layout = splitSidePanelPane(layout, 'pane-notes', 'ai', 'vertical', { + paneId: 'pane-ai', + splitId: 'split-root', + }, 400); + assert.equal(layout.root.type, 'split'); + if (layout.root.type !== 'split') return; + + assert.deepEqual( + getSidePanelSplitChildPresentation(layout.root.children[0], 0.75, 'pane-ai'), + { flexGrow: 0, hidden: true }, + ); + assert.deepEqual( + getSidePanelSplitChildPresentation(layout.root.children[1], 0.25, 'pane-ai'), + { flexGrow: 1, hidden: false }, + ); + assert.deepEqual( + getSidePanelSplitChildPresentation(layout.root.children[0], 0.75, null), + { flexGrow: 0.75, hidden: false }, + ); +}); + test('side panel tab order falls back to the default order', () => { assert.deepEqual(normalizeTerminalSidePanelTabOrder(null), TERMINAL_SIDE_PANEL_TAB_DEFAULT_ORDER); // Partial / dirty lists keep known ids in order and append the rest of the defaults. @@ -228,6 +265,13 @@ test('side panel layout state is initialized before callbacks read it', () => { assert.ok(layoutStateIndex < statusCallbackIndex); }); +test('side panel focus actions are forwarded through the tab bridge', () => { + const bridgeSource = readFileSync(new URL('./TerminalLayerTabBridge.tsx', import.meta.url), 'utf8'); + + assert.match(bridgeSource, /handleMaximizeSidePanelPane: s\.handleMaximizeSidePanelPane/); + assert.match(bridgeSource, /handleRestoreSidePanelLayout: s\.handleRestoreSidePanelLayout/); +}); + test('split dragging previews locally, commits once, and cleans up on every exit path', () => { const sectionSource = readFileSync(new URL('./TerminalLayerSidePanelSection.tsx', import.meta.url), 'utf8'); diff --git a/components/terminalLayer/TerminalLayerSidePanelSection.tsx b/components/terminalLayer/TerminalLayerSidePanelSection.tsx index 871f50eb7..58f61ea8d 100644 --- a/components/terminalLayer/TerminalLayerSidePanelSection.tsx +++ b/components/terminalLayer/TerminalLayerSidePanelSection.tsx @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Activity, FolderTree, History, MessageSquare, NotebookText, Palette, PanelLeft, PanelRight, Play, SplitSquareHorizontal, SplitSquareVertical, X } from 'lucide-react'; +import { Activity, FolderTree, History, Maximize2, MessageSquare, Minimize2, NotebookText, Palette, PanelLeft, PanelRight, Play, SplitSquareHorizontal, SplitSquareVertical, X } from 'lucide-react'; import { buildSidePanelChromeThemeFromTerminalTheme, buildTerminalSidePanelCssVars, @@ -41,8 +41,10 @@ import { canSplitSidePanelPaneAtSize, collectSidePanelPanes, getFocusedSidePanelPane, + getPaneZoomShortcutLabel, getSidePanelNodeMinimumPixels, getSidePanelSplitResizeBounds, + sidePanelNodeContainsPane, SIDE_PANEL_SPLIT_DIVIDER_PIXELS, type SidePanelLayout, type SidePanelLayoutNode, @@ -65,6 +67,16 @@ MemoizedSidePanelMountedContent.displayName = 'MemoizedSidePanelMountedContent'; type SidePanelContext = Record; const SIDE_PANEL_TAB_DRAG_MIME = 'application/x-netcatty-sidepanel-tab'; +export function getSidePanelSplitChildPresentation( + child: SidePanelLayoutNode, + normalFlexGrow: number, + maximizedPaneId: string | null, +): { flexGrow: number; hidden: boolean } { + if (!maximizedPaneId) return { flexGrow: normalFlexGrow, hidden: false }; + const visible = sidePanelNodeContainsPane(child, maximizedPaneId); + return { flexGrow: visible ? 1 : 0, hidden: !visible }; +} + type SidePanelTabItem = { id: SidePanelTab; label: string; @@ -169,12 +181,14 @@ function SidePanelPaneHost({ function SidePanelSplitView({ node, children, + maximizedPaneId, onResize, separator, resizeLabel, }: { node: SidePanelSplitNode; children: React.ReactNode[]; + maximizedPaneId: string | null; onResize: (splitId: string, sizes: number[]) => void; separator: string; resizeLabel: string; @@ -271,12 +285,31 @@ function SidePanelSplitView({ > {children.map((child, index) => ( -
- {child} -
+ {(() => { + const presentation = getSidePanelSplitChildPresentation( + node.children[index], + renderedSizes[index], + maximizedPaneId, + ); + return ( +
+ {child} +
+ ); + })()} {index < children.length - 1 && (
startResize(event, index)} + style={{ display: maximizedPaneId ? 'none' : undefined }} onKeyDown={(event) => { const decrease = node.direction === 'vertical' ? event.key === 'ArrowLeft' @@ -385,6 +419,7 @@ function SidePanelLayoutTree({ return ( 0 - ? clampTerminalSidePanelWidth( - requestedShellWidth, - availableSurfaceWidth, - sidePanelContentMinimumWidth, - ) + ? (maximizedPaneId + ? requestedShellWidth + : clampTerminalSidePanelWidth( + requestedShellWidth, + availableSurfaceWidth, + sidePanelContentMinimumWidth, + )) : 0; const handleSidePanelResizeStart = useCallback((event: React.MouseEvent) => { @@ -863,6 +913,10 @@ function TerminalLayerSidePanelInner({ ctx }: { ctx: SidePanelContext }) { ? getFocusedSidePanelPane(activeSidePanelLayout) : null; const focusedPaneHost = focusedPane ? paneHosts.get(focusedPane.tool) ?? null : null; + const maximizedPane = activeSidePanelLayout?.maximizedPaneId + ? collectSidePanelPanes(activeSidePanelLayout.root) + .find((pane) => pane.id === activeSidePanelLayout.maximizedPaneId) ?? null + : null; const [focusedPaneSplitAvailability, setFocusedPaneSplitAvailability] = useState({ horizontal: false, vertical: false, @@ -956,8 +1010,11 @@ function TerminalLayerSidePanelInner({ ctx }: { ctx: SidePanelContext }) { ref={shellRef} style={{ width: shellWidth, - maxWidth: getTerminalSidePanelMaxWidth(availableSurfaceWidth), + maxWidth: maximizedPaneId + ? availableSurfaceWidth + : getTerminalSidePanelMaxWidth(availableSurfaceWidth), contain: 'layout paint style', + transition: 'width 160ms ease, max-width 160ms ease', }} className={cn( 'flex-shrink-0 h-full relative z-20', @@ -967,7 +1024,7 @@ function TerminalLayerSidePanelInner({ ctx }: { ctx: SidePanelContext }) { data-section="terminal-side-panel-shell" data-side-panel-position={sidePanelPosition} > - {isSidePanelOpenForCurrentTab && !isAiShellForceHidden && ( + {isSidePanelOpenForCurrentTab && !isAiShellForceHidden && !maximizedPaneId && (
-
- = MAX_SIDE_PANEL_PANES - || !focusedPaneSplitAvailability.horizontal - } - onSelect={handleSplitSidePanelSelect} - t={t} - buttonColor={sidePanelTheme.mutedFg} - /> - = MAX_SIDE_PANEL_PANES - || !focusedPaneSplitAvailability.vertical - } - onSelect={handleSplitSidePanelSelect} - t={t} - buttonColor={sidePanelTheme.mutedFg} - /> +
+ {maximizedPane && ( +
+ + {t('terminal.layer.focusedPane')}: {sidePanelToolLabels.get(maximizedPane.tool) ?? maximizedPane.tool} + + + · {paneZoomShortcutLabel ? `${paneZoomShortcutLabel} / ` : ''}Esc + +
+ )} + {focusedPane && ( + + + { + if (maximizedPane) handleRestoreSidePanelLayout(); + else handleMaximizeSidePanelPane(focusedPane.id); + }} + > + {maximizedPane ? : } + + + + {maximizedPane + ? t('terminal.layer.restorePanes') + : t('terminal.layer.focusPane')} + + + )} + {!maximizedPane && ( + <> + = MAX_SIDE_PANEL_PANES + || !focusedPaneSplitAvailability.horizontal + } + onSelect={handleSplitSidePanelSelect} + t={t} + buttonColor={sidePanelTheme.mutedFg} + /> + = MAX_SIDE_PANEL_PANES + || !focusedPaneSplitAvailability.vertical + } + onSelect={handleSplitSidePanelSelect} + t={t} + buttonColor={sidePanelTheme.mutedFg} + /> + + )} void) | null>; toggleSidePanelRef?: React.MutableRefObject<(() => void) | null>; + sidePanelPaneZoomRef?: React.MutableRefObject; // Session rename onStartSessionRename?: (sessionId: string) => void; onSubmitSessionRename?: (sessionId?: string, name?: string) => void; diff --git a/components/terminalLayer/TerminalLayerTabBridge.tsx b/components/terminalLayer/TerminalLayerTabBridge.tsx index 4a3f48d2d..83c1420e6 100644 --- a/components/terminalLayer/TerminalLayerTabBridge.tsx +++ b/components/terminalLayer/TerminalLayerTabBridge.tsx @@ -437,6 +437,8 @@ export function TerminalLayerTabBridge({ stableRef }: { stableRef: StableRef }) handleHistoryDelete: s.handleHistoryDelete, handleHistoryRun: s.handleHistoryRun, handleFocusSidePanelPane: s.handleFocusSidePanelPane, + handleMaximizeSidePanelPane: s.handleMaximizeSidePanelPane, + handleRestoreSidePanelLayout: s.handleRestoreSidePanelLayout, handleSplitSidePanelPane: s.handleSplitSidePanelPane, handleCloseSidePanelPane: s.handleCloseSidePanelPane, handleResizeSidePanelSplit: s.handleResizeSidePanelSplit, diff --git a/components/terminalLayerMemo.ts b/components/terminalLayerMemo.ts index c792a2ef0..327221f46 100644 --- a/components/terminalLayerMemo.ts +++ b/components/terminalLayerMemo.ts @@ -77,6 +77,7 @@ export const terminalLayerAreEqual = ( prev.updateSnippetPackages === next.updateSnippetPackages && prev.toggleScriptsSidePanelRef === next.toggleScriptsSidePanelRef && prev.toggleSidePanelRef === next.toggleSidePanelRef && + prev.sidePanelPaneZoomRef === next.sidePanelPaneZoomRef && prev.identities === next.identities // shellHistory intentionally omitted — History panel reads shellHistoryStore. ); diff --git a/domain/sidePanelLayout.test.ts b/domain/sidePanelLayout.test.ts index 1fbcc36c9..d486cb953 100644 --- a/domain/sidePanelLayout.test.ts +++ b/domain/sidePanelLayout.test.ts @@ -10,12 +10,108 @@ import { focusSidePanelPane, getSidePanelNodeMinimumPixels, getSidePanelSplitResizeBounds, + maximizeSidePanelPane, resizeSidePanelSplit, + restoreSidePanelLayout, selectSidePanelTool, + sidePanelNodeContainsPane, + getAvailablePaneZoomController, + getPaneZoomShortcutLabel, sidePanelLayoutHasTool, splitSidePanelPane, } from './sidePanelLayout.ts'; +test('pane zoom routing selects the controller for the active surface', () => { + const unavailable = { + getState: () => 'unavailable' as const, + toggle: () => false, + focus: () => false, + unfocus: () => false, + }; + const focused = { + getState: () => 'focused' as const, + toggle: () => true, + focus: () => false, + unfocus: () => true, + }; + + assert.equal(getAvailablePaneZoomController([null, unavailable, focused]), focused); + assert.equal(getAvailablePaneZoomController([null, unavailable]), null); +}); + +test('focus hints show the active configurable pane zoom shortcut', () => { + const bindings = [{ + id: 'toggle-pane-zoom', + mac: '⌥ + M', + pc: 'Alt + M', + }]; + + assert.equal(getPaneZoomShortcutLabel(bindings, 'mac'), '⌥+M'); + assert.equal(getPaneZoomShortcutLabel(bindings, 'pc'), 'Alt+M'); + assert.equal(getPaneZoomShortcutLabel(bindings, 'disabled'), ''); +}); + +test('maximizing and restoring a pane preserves the exact split tree and ratios', () => { + let layout = createSidePanelLayout('notes', 'pane-notes'); + layout = splitSidePanelPane(layout, 'pane-notes', 'ai', 'vertical', { + paneId: 'pane-ai', + splitId: 'split-root', + }, 400); + layout = resizeSidePanelSplit(layout, 'split-root', [3, 1]); + const originalRoot = layout.root; + + const maximized = maximizeSidePanelPane(layout, 'pane-notes'); + assert.equal(maximized.maximizedPaneId, 'pane-notes'); + assert.equal(maximized.focusedPaneId, 'pane-notes'); + assert.equal(maximized.root, originalRoot); + + const restored = restoreSidePanelLayout(maximized); + assert.equal(restored.maximizedPaneId, null); + assert.equal(restored.focusedPaneId, 'pane-notes'); + assert.equal(restored.root, originalRoot); + assert.deepEqual(restored.root.type === 'split' ? restored.root.sizes : [], [0.75, 0.25]); +}); + +test('a single side-panel pane can focus over the terminal workspace', () => { + const layout = createSidePanelLayout('sftp', 'pane-sftp'); + const maximized = maximizeSidePanelPane(layout, 'pane-sftp'); + + assert.equal(maximized.maximizedPaneId, 'pane-sftp'); + assert.equal(restoreSidePanelLayout(maximized).root, layout.root); +}); + +test('closing the maximized pane restores the remaining layout with a valid focus', () => { + let layout = createSidePanelLayout('notes', 'pane-notes'); + layout = splitSidePanelPane(layout, 'pane-notes', 'ai', 'vertical', { + paneId: 'pane-ai', + splitId: 'split-root', + }, 400); + layout = maximizeSidePanelPane(layout, 'pane-ai'); + + const closed = closeSidePanelPane(layout, 'pane-ai'); + assert.ok(closed); + assert.equal(closed.maximizedPaneId, null); + assert.equal(closed.focusedPaneId, 'pane-notes'); +}); + +test('maximized rendering can keep the full tree mounted and identify only its visible branch', () => { + let layout = createSidePanelLayout('notes', 'pane-notes'); + layout = splitSidePanelPane(layout, 'pane-notes', 'ai', 'vertical', { + paneId: 'pane-ai', + splitId: 'split-root', + }, 400); + layout = splitSidePanelPane(layout, 'pane-ai', 'system', 'horizontal', { + paneId: 'pane-system', + splitId: 'split-nested', + }, 300); + assert.equal(layout.root.type, 'split'); + if (layout.root.type !== 'split') return; + + assert.equal(sidePanelNodeContainsPane(layout.root.children[0], 'pane-system'), false); + assert.equal(sidePanelNodeContainsPane(layout.root.children[1], 'pane-system'), true); + assert.equal(sidePanelNodeContainsPane(layout.root, 'missing-pane'), false); +}); + test('panes smaller than two minimum cells cannot be split again', () => { const layout = createSidePanelLayout('notes', 'pane-notes'); const tooSmall = splitSidePanelPane(layout, 'pane-notes', 'ai', 'vertical', { diff --git a/domain/sidePanelLayout.ts b/domain/sidePanelLayout.ts index 2168775b2..1e21aac15 100644 --- a/domain/sidePanelLayout.ts +++ b/domain/sidePanelLayout.ts @@ -28,8 +28,35 @@ export type SidePanelLayoutNode = SidePanelPaneNode | SidePanelSplitNode; export type SidePanelLayout = { root: SidePanelLayoutNode; focusedPaneId: string; + maximizedPaneId: string | null; }; +export type SidePanelPaneZoomState = 'unavailable' | 'focusable' | 'focused'; + +export type SidePanelPaneZoomController = { + getState: () => SidePanelPaneZoomState; + toggle: () => boolean; + focus: () => boolean; + unfocus: () => boolean; +}; + +export function getAvailablePaneZoomController( + controllers: Array, +): SidePanelPaneZoomController | null { + return controllers.find((controller) => ( + controller && controller.getState() !== 'unavailable' + )) ?? null; +} + +export function getPaneZoomShortcutLabel( + keyBindings: Array<{ id: string; mac: string; pc: string }> | undefined, + hotkeyScheme: 'mac' | 'pc' | 'disabled' | undefined, +): string { + if (!keyBindings || !hotkeyScheme || hotkeyScheme === 'disabled') return ''; + const binding = keyBindings.find((entry) => entry.id === 'toggle-pane-zoom'); + return (hotkeyScheme === 'mac' ? binding?.mac : binding?.pc)?.replace(/ \+ /g, '+') ?? ''; +} + export const MAX_SIDE_PANEL_PANES = 8; export const MIN_SIDE_PANEL_PANE_PIXELS = 80; export const MIN_SIDE_PANEL_PANE_RATIO = 0.04; @@ -93,6 +120,7 @@ export function createSidePanelLayout( return { root: { id: paneId, type: 'pane', tool }, focusedPaneId: paneId, + maximizedPaneId: null, }; } @@ -101,6 +129,14 @@ export function collectSidePanelPanes(node: SidePanelLayoutNode): SidePanelPaneN return node.children.flatMap(collectSidePanelPanes); } +export function sidePanelNodeContainsPane( + node: SidePanelLayoutNode, + paneId: string, +): boolean { + if (node.type === 'pane') return node.id === paneId; + return node.children.some((child) => sidePanelNodeContainsPane(child, paneId)); +} + export function sidePanelLayoutHasTool( layout: SidePanelLayout | null | undefined, tool: SidePanelTool, @@ -119,7 +155,30 @@ export function focusSidePanelPane( ): SidePanelLayout { if (layout.focusedPaneId === paneId) return layout; if (!collectSidePanelPanes(layout.root).some((pane) => pane.id === paneId)) return layout; - return { ...layout, focusedPaneId: paneId }; + return { + ...layout, + focusedPaneId: paneId, + maximizedPaneId: layout.maximizedPaneId ? paneId : null, + }; +} + +export function maximizeSidePanelPane( + layout: SidePanelLayout, + paneId: string, +): SidePanelLayout { + if (layout.maximizedPaneId === paneId) return layout; + if (!collectSidePanelPanes(layout.root).some((pane) => pane.id === paneId)) return layout; + return { + ...layout, + focusedPaneId: paneId, + maximizedPaneId: paneId, + }; +} + +export function restoreSidePanelLayout(layout: SidePanelLayout): SidePanelLayout { + return layout.maximizedPaneId === null + ? layout + : { ...layout, maximizedPaneId: null }; } export function selectSidePanelTool( @@ -152,6 +211,7 @@ export function splitSidePanelPane( availableAxisLength: number, ): SidePanelLayout { const panes = collectSidePanelPanes(layout.root); + if (layout.maximizedPaneId) return layout; const occupied = panes.find((pane) => pane.tool === tool); if (occupied) return focusSidePanelPane(layout, occupied.id); if (panes.length >= MAX_SIDE_PANEL_PANES) return layout; @@ -179,6 +239,7 @@ export function splitSidePanelPane( return { root: insert(layout.root), focusedPaneId: ids.paneId, + maximizedPaneId: null, }; } @@ -223,6 +284,7 @@ export function closeSidePanelPane( return { root, focusedPaneId: existingFocus?.id ?? remaining[fallbackIndex].id, + maximizedPaneId: null, }; } diff --git a/domain/workspaceSidePanelTabRemap.test.ts b/domain/workspaceSidePanelTabRemap.test.ts index 4e68346ff..d361a1f10 100644 --- a/domain/workspaceSidePanelTabRemap.test.ts +++ b/domain/workspaceSidePanelTabRemap.test.ts @@ -30,8 +30,8 @@ test('promote copies preferred member open tool onto the new workspace tab', () }); test('promote copies split layouts onto the new workspace tab', () => { - const layoutA = { focusedPaneId: 'pane-a', root: { type: 'pane', id: 'pane-a', tool: 'ai' } }; - const layoutB = { focusedPaneId: 'pane-b', root: { type: 'pane', id: 'pane-b', tool: 'sftp' } }; + const layoutA = { focusedPaneId: 'pane-a', maximizedPaneId: null, root: { type: 'pane', id: 'pane-a', tool: 'ai' } }; + const layoutB = { focusedPaneId: 'pane-b', maximizedPaneId: null, root: { type: 'pane', id: 'pane-b', tool: 'sftp' } }; const source = new Map([ ['term-a', layoutA], ['term-b', layoutB],