diff --git a/src/main/persistence.test.ts b/src/main/persistence.test.ts index 3140f3ce7..fd87be32c 100644 --- a/src/main/persistence.test.ts +++ b/src/main/persistence.test.ts @@ -3051,6 +3051,38 @@ describe('Store', () => { expect(store.getUI().rightSidebarTab).toBe('checks') }) + it('preserves explicit rightSidebarExplorerView in persisted UI', async () => { + writeDataFile({ + schemaVersion: 1, + repos: [], + worktreeMeta: {}, + settings: {}, + ui: { rightSidebarTab: 'explorer', rightSidebarExplorerView: 'search' }, + githubCache: { pr: {}, issue: {} }, + workspaceSession: {} + }) + + const store = await createStore() + expect(store.getUI().rightSidebarTab).toBe('explorer') + expect(store.getUI().rightSidebarExplorerView).toBe('search') + }) + + it('maps legacy persisted search tab to the Explorer search view', async () => { + writeDataFile({ + schemaVersion: 1, + repos: [], + worktreeMeta: {}, + settings: {}, + ui: { rightSidebarTab: 'search' }, + githubCache: { pr: {}, issue: {} }, + workspaceSession: {} + }) + + const store = await createStore() + expect(store.getUI().rightSidebarTab).toBe('search') + expect(store.getUI().rightSidebarExplorerView).toBe('search') + }) + it('normalizes invalid rightSidebarTab in persisted UI', async () => { writeDataFile({ schemaVersion: 1, diff --git a/src/main/persistence.ts b/src/main/persistence.ts index c4f6546dc..61b35183f 100644 --- a/src/main/persistence.ts +++ b/src/main/persistence.ts @@ -433,6 +433,20 @@ function normalizeRightSidebarTab(tab: unknown): PersistedState['ui']['rightSide return getDefaultUIState().rightSidebarTab } +function normalizeRightSidebarExplorerView( + view: unknown, + tab?: unknown +): PersistedState['ui']['rightSidebarExplorerView'] { + // Why: older builds persisted Search as a standalone activity tab. + if (tab === 'search') { + return 'search' + } + if (view === 'files' || view === 'search') { + return view + } + return getDefaultUIState().rightSidebarExplorerView +} + function normalizeNotificationSettings(value: unknown): NotificationSettings { const defaults = getDefaultNotificationSettings() const candidate = @@ -3279,6 +3293,10 @@ export class Store { sortBy: normalizeSortBy(this.state.ui?.sortBy), projectOrderBy: normalizeProjectOrderBy(this.state.ui?.projectOrderBy), rightSidebarTab: normalizeRightSidebarTab(this.state.ui?.rightSidebarTab), + rightSidebarExplorerView: normalizeRightSidebarExplorerView( + this.state.ui?.rightSidebarExplorerView, + this.state.ui?.rightSidebarTab + ), worktreeCardProperties: normalizeWorktreeCardProperties( this.state.ui?.worktreeCardProperties ), @@ -3308,6 +3326,22 @@ export class Store { ...getDefaultUIState(), ...stripMainOwnedTelemetryMarkerFromUI(this.state.ui) } + const nextRightSidebarTab = + sanitizedUpdates.rightSidebarTab !== undefined + ? normalizeRightSidebarTab(sanitizedUpdates.rightSidebarTab) + : normalizeRightSidebarTab(this.state.ui?.rightSidebarTab) + const nextRightSidebarExplorerView = + sanitizedUpdates.rightSidebarExplorerView !== undefined + ? normalizeRightSidebarExplorerView( + sanitizedUpdates.rightSidebarExplorerView, + nextRightSidebarTab + ) + : sanitizedUpdates.rightSidebarTab === 'search' + ? 'search' + : normalizeRightSidebarExplorerView( + this.state.ui?.rightSidebarExplorerView, + nextRightSidebarTab + ) this.state.ui = { ...currentUI, ...sanitizedUpdates, @@ -3320,10 +3354,8 @@ export class Store { projectOrderBy: updates.projectOrderBy ? normalizeProjectOrderBy(updates.projectOrderBy) : normalizeProjectOrderBy(this.state.ui?.projectOrderBy), - rightSidebarTab: - sanitizedUpdates.rightSidebarTab !== undefined - ? normalizeRightSidebarTab(sanitizedUpdates.rightSidebarTab) - : normalizeRightSidebarTab(this.state.ui?.rightSidebarTab), + rightSidebarTab: nextRightSidebarTab, + rightSidebarExplorerView: nextRightSidebarExplorerView, worktreeCardProperties: sanitizedUpdates.worktreeCardProperties !== undefined ? normalizeWorktreeCardProperties(sanitizedUpdates.worktreeCardProperties) diff --git a/src/main/runtime/rpc/methods/client-ui.test.ts b/src/main/runtime/rpc/methods/client-ui.test.ts index cd4d1f6e5..b2d003202 100644 --- a/src/main/runtime/rpc/methods/client-ui.test.ts +++ b/src/main/runtime/rpc/methods/client-ui.test.ts @@ -129,6 +129,7 @@ describe('client UI RPC methods', () => { ...getDefaultUIState(), rightSidebarOpen: false, rightSidebarTab: 'checks', + rightSidebarExplorerView: 'search', showActiveOnly: true, filterRepoIds: ['repo-1'] } @@ -142,6 +143,7 @@ describe('client UI RPC methods', () => { makeRequest('ui.set', { rightSidebarOpen: false, rightSidebarTab: 'checks', + rightSidebarExplorerView: 'search', showActiveOnly: true, hideSleepingWorkspaces: true, filterRepoIds: ['repo-1'] @@ -151,6 +153,7 @@ describe('client UI RPC methods', () => { expect(runtime.updateUIState).toHaveBeenCalledWith({ rightSidebarOpen: false, rightSidebarTab: 'checks', + rightSidebarExplorerView: 'search', showActiveOnly: true, hideSleepingWorkspaces: true, filterRepoIds: ['repo-1'] diff --git a/src/main/runtime/rpc/methods/client-ui.ts b/src/main/runtime/rpc/methods/client-ui.ts index 4823029d1..ad7dac063 100644 --- a/src/main/runtime/rpc/methods/client-ui.ts +++ b/src/main/runtime/rpc/methods/client-ui.ts @@ -148,6 +148,7 @@ const UiUpdate = z rightSidebarTab: z .enum(['explorer', 'search', 'vault', 'source-control', 'checks', 'ports']) .optional(), + rightSidebarExplorerView: z.enum(['files', 'search']).optional(), rightSidebarWidth: z.number().finite().optional(), groupBy: z.enum(['none', 'workspace-status', 'repo', 'pr-status']).optional(), showWorkspaceLineage: z.boolean().optional(), diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 0c7b82ebb..cdf2311ca 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -356,8 +356,8 @@ function App(): React.JSX.Element { toggleRightSidebar: s.toggleRightSidebar, setRightSidebarOpen: s.setRightSidebarOpen, setRightSidebarTab: s.setRightSidebarTab, - seedFileSearchQuery: s.seedFileSearchQuery, - seedFileSearchIncludePattern: s.seedFileSearchIncludePattern, + showRightSidebarFiles: s.showRightSidebarFiles, + showRightSidebarSearch: s.showRightSidebarSearch, setActiveView: s.setActiveView, updateSettings: s.updateSettings, pruneLastVisitedTimestamps: s.pruneLastVisitedTimestamps, @@ -527,6 +527,7 @@ function App(): React.JSX.Element { const rightSidebarWidth = useAppStore((s) => s.rightSidebarWidth) const rightSidebarOpen = useAppStore((s) => s.rightSidebarOpen) const rightSidebarTab = useAppStore((s) => s.rightSidebarTab) + const rightSidebarExplorerView = useAppStore((s) => s.rightSidebarExplorerView) const isFullScreen = useAppStore((s) => s.isFullScreen) const settings = useAppStore((s) => s.settings) const dictationState = useAppStore((s) => s.dictationState) @@ -1117,6 +1118,7 @@ function App(): React.JSX.Element { sidebarWidth, rightSidebarOpen, rightSidebarTab, + rightSidebarExplorerView, rightSidebarWidth, groupBy, sortBy, @@ -1142,6 +1144,7 @@ function App(): React.JSX.Element { sidebarWidth, rightSidebarOpen, rightSidebarTab, + rightSidebarExplorerView, rightSidebarWidth, groupBy, sortBy, @@ -1293,11 +1296,7 @@ function App(): React.JSX.Element { const canRevealRightSidebar = canShowRightSidebarForView(activeView) const openSearchSidebar = (query: string | null): void => { - if (query && activeWorktreeId) { - actions.seedFileSearchQuery(activeWorktreeId, query) - } - actions.setRightSidebarTab('search') - actions.setRightSidebarOpen(true) + actions.showRightSidebarSearch(query ? { query } : undefined) } if (matchShortcut('sidebar.search.toggle') && canRevealRightSidebar) { @@ -1311,12 +1310,9 @@ function App(): React.JSX.Element { if (selectedFolderRelativePath !== null && activeWorktreeId) { e.preventDefault() notifyTerminalCapture('sidebar.search.toggle') - actions.seedFileSearchIncludePattern( - activeWorktreeId, - folderRelativePathToIncludeGlob(selectedFolderRelativePath) - ) - actions.setRightSidebarTab('search') - actions.setRightSidebarOpen(true) + actions.showRightSidebarSearch({ + includePattern: folderRelativePathToIncludeGlob(selectedFolderRelativePath) + }) return } @@ -1471,8 +1467,7 @@ function App(): React.JSX.Element { if (matchShortcut('sidebar.explorer.toggle')) { e.preventDefault() notifyTerminalCapture('sidebar.explorer.toggle') - actions.setRightSidebarTab('explorer') - actions.setRightSidebarOpen(true) + actions.showRightSidebarFiles() return } @@ -1997,7 +1992,11 @@ function App(): React.JSX.Element { { + if (entry.type === Button && entry.props['aria-label'] === 'Search') { + found = entry + } + }) + if (!found) { + throw new Error('search button not found') + } + return found +} + function findCollapseAllButton(node: unknown): ReactElementLike { let found: ReactElementLike | null = null visit(node, (entry) => { @@ -226,6 +239,7 @@ function makeToolbar(overrides: Partial[0 onToggleGitIgnoredFiles: vi.fn(), showDotfiles: true, onToggleDotfiles: vi.fn(), + onSearch: vi.fn(), ...overrides }) } @@ -261,6 +275,17 @@ describe('FileExplorerToolbar', () => { expect(label.props.className).toContain('min-w-0') }) + it('fires the search action from the icon button', () => { + const onSearch = vi.fn() + const element = makeToolbar({ onSearch }) + + const button = findSearchButton(element) + ;(button.props.onClick as () => void)() + + expect(onSearch).toHaveBeenCalledTimes(1) + expect(hasIcon(button, Search)).toBe(true) + }) + it('disables the refresh button and shows a spinner while refreshing', () => { const element = makeToolbar({ refresh: makeRefreshState({ isRefreshing: true, showRefreshSpinner: true }) @@ -284,7 +309,8 @@ describe('FileExplorerToolbar', () => { ;(button.props.onClick as () => void)() expect(onCollapseAll).toHaveBeenCalledTimes(1) - expect(button.props.disabled).toBe(false) + expect(button.props.disabled).toBeUndefined() + expect(button.props['aria-disabled']).toBe(false) expect(hasIcon(button, ListCollapse)).toBe(true) }) @@ -293,10 +319,25 @@ describe('FileExplorerToolbar', () => { const button = findCollapseAllButton(element) - expect(button.props.disabled).toBe(true) + expect(button.props.disabled).toBeUndefined() + expect(button.props['aria-disabled']).toBe(true) + expect(button.props.className).toContain('opacity-50') + expect(button.props.className).toContain('cursor-not-allowed') expect(hasIcon(button, ListCollapse)).toBe(true) }) + it('keeps disabled collapse all clicks from firing', () => { + const onCollapseAll = vi.fn() + const preventDefault = vi.fn() + const element = makeToolbar({ canCollapseAll: false, onCollapseAll }) + + const button = findCollapseAllButton(element) + ;(button.props.onClick as (event: { preventDefault: () => void }) => void)({ preventDefault }) + + expect(preventDefault).toHaveBeenCalledTimes(1) + expect(onCollapseAll).not.toHaveBeenCalled() + }) + it('puts the git ignored visibility toggle in the overflow menu', () => { const onToggleGitIgnoredFiles = vi.fn() const element = makeToolbar({ onToggleGitIgnoredFiles }) @@ -334,6 +375,7 @@ describe('FileExplorerToolbar', () => { const element = makeToolbar() expect(getToolbarButtonLabels(element)).toEqual([ + 'Search', 'Collapse All', 'Refresh Explorer', 'More Explorer Actions' diff --git a/src/renderer/src/components/right-sidebar/FileExplorer.tsx b/src/renderer/src/components/right-sidebar/FileExplorer.tsx index 46ca44ad3..062952e03 100644 --- a/src/renderer/src/components/right-sidebar/FileExplorer.tsx +++ b/src/renderer/src/components/right-sidebar/FileExplorer.tsx @@ -1,11 +1,14 @@ /* eslint-disable max-lines -- Why: FileExplorer coordinates tree data, selection, drag/drop, and virtual rows; splitting it during this merge would obscure the interaction invariants. */ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useVirtualizer } from '@tanstack/react-virtual' +import { ArrowLeft } from 'lucide-react' import { useAppStore } from '@/store' import { useActiveWorktree, useRepoById } from '@/store/selectors' import { basename, dirname } from '@/lib/path' import { folderRelativePathToIncludeGlob } from './file-search-include-pattern' +import { Button } from '@/components/ui/button' import { ScrollArea } from '@/components/ui/scroll-area' +import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' import { cn } from '@/lib/utils' import { isGitRepoKind } from '../../../../shared/repo-kind' import { shouldResetFileExplorerForVisibleWorktree } from './file-explorer-reset' @@ -36,8 +39,46 @@ import type { TreeNode } from './file-explorer-types' import { useFileExplorerSelection } from './useFileExplorerSelection' import { useFileExplorerVisibleRowProjection } from './useFileExplorerVisibleRowProjection' import { translate } from '@/i18n/i18n' +import SearchPanel from './Search' -function FileExplorerInner(): React.JSX.Element { +function ExplorerSearchSubview(): React.JSX.Element { + const showRightSidebarFiles = useAppStore((s) => s.showRightSidebarFiles) + + return ( +
+
+ + + + + + {translate('auto.components.right.sidebar.FileExplorer.4da4d89845', 'Back to Explorer')} + + + + {translate('auto.components.right.sidebar.FileExplorer.6ed5ce817b', 'Search')} + +
+
+ +
+
+ ) +} + +function FileExplorerFiles(): React.JSX.Element { const activeWorktreeId = useAppStore((s) => s.activeWorktreeId) const activeWorktree = useActiveWorktree() const activeRepo = useRepoById(activeWorktree?.repoId ?? null) @@ -46,6 +87,7 @@ function FileExplorerInner(): React.JSX.Element { const collapseAllDirs = useAppStore((s) => s.collapseAllDirs) const collapseDirSubtree = useAppStore((s) => s.collapseDirSubtree) const toggleDir = useAppStore((s) => s.toggleDir) + const showRightSidebarSearch = useAppStore((s) => s.showRightSidebarSearch) const pendingExplorerReveal = useAppStore((s) => s.pendingExplorerReveal) const clearPendingExplorerReveal = useAppStore((s) => s.clearPendingExplorerReveal) const openFile = useAppStore((s) => s.openFile) @@ -397,22 +439,19 @@ function FileExplorerInner(): React.JSX.Element { }, [activeWorktreeId, collapseDirSubtree] ) - const seedFileSearchIncludePattern = useAppStore((s) => s.seedFileSearchIncludePattern) - const setRightSidebarTab = useAppStore((s) => s.setRightSidebarTab) - const setRightSidebarOpen = useAppStore((s) => s.setRightSidebarOpen) + const handleOpenSearch = useCallback(() => { + showRightSidebarSearch() + }, [showRightSidebarSearch]) const handleFindInFolder = useCallback( (node: TreeNode) => { if (!activeWorktreeId || !node.isDirectory) { return } - seedFileSearchIncludePattern( - activeWorktreeId, - folderRelativePathToIncludeGlob(node.relativePath) - ) - setRightSidebarTab('search') - setRightSidebarOpen(true) + showRightSidebarSearch({ + includePattern: folderRelativePathToIncludeGlob(node.relativePath) + }) }, - [activeWorktreeId, seedFileSearchIncludePattern, setRightSidebarTab, setRightSidebarOpen] + [activeWorktreeId, showRightSidebarSearch] ) const handleAddFolderAsProject = useCallback( @@ -470,6 +509,7 @@ function FileExplorerInner(): React.JSX.Element { onToggleGitIgnoredFiles={toggleGitIgnoredFiles} showDotfiles={showDotfiles} onToggleDotfiles={handleToggleDotfiles} + onSearch={handleOpenSearch} /> s.rightSidebarExplorerView) + return explorerView === 'search' ? : +} + +export default React.memo(FileExplorer) diff --git a/src/renderer/src/components/right-sidebar/FileExplorerToolbar.tsx b/src/renderer/src/components/right-sidebar/FileExplorerToolbar.tsx index 341b2e0a4..50bcb9bf2 100644 --- a/src/renderer/src/components/right-sidebar/FileExplorerToolbar.tsx +++ b/src/renderer/src/components/right-sidebar/FileExplorerToolbar.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { Ellipsis, ListCollapse, Loader2, RefreshCw } from 'lucide-react' +import { Ellipsis, ListCollapse, Loader2, RefreshCw, Search } from 'lucide-react' import { Button } from '@/components/ui/button' import { DropdownMenu, @@ -11,6 +11,7 @@ import { import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' import { WorktreeOpenInMenuItems } from '@/components/sidebar/WorktreeOpenInMenu' import { translate } from '@/i18n/i18n' +import { cn } from '@/lib/utils' type FileExplorerToolbarProps = { repoName: string @@ -28,6 +29,7 @@ type FileExplorerToolbarProps = { onToggleGitIgnoredFiles: () => void showDotfiles: boolean onToggleDotfiles: () => void + onSearch: () => void } export function FileExplorerToolbar({ @@ -41,7 +43,8 @@ export function FileExplorerToolbar({ showGitIgnoredFiles, onToggleGitIgnoredFiles, showDotfiles, - onToggleDotfiles + onToggleDotfiles, + onSearch }: FileExplorerToolbarProps): React.JSX.Element { return (
@@ -58,12 +61,42 @@ export function FileExplorerToolbar({ variant="ghost" size="icon-xs" className="text-muted-foreground hover:text-foreground" + aria-label={translate( + 'auto.components.right.sidebar.FileExplorerToolbar.693cbeadd0', + 'Search' + )} + onClick={onSearch} + > + + + + + {translate('auto.components.right.sidebar.FileExplorerToolbar.693cbeadd0', 'Search')} + + + + + diff --git a/src/renderer/src/components/right-sidebar/Search.tsx b/src/renderer/src/components/right-sidebar/Search.tsx index 48d5b7783..d44d141a1 100644 --- a/src/renderer/src/components/right-sidebar/Search.tsx +++ b/src/renderer/src/components/right-sidebar/Search.tsx @@ -35,6 +35,7 @@ export default function Search(): React.JSX.Element { const fileSearchLoading = searchState?.loading ?? false const fileSearchCollapsedFiles = searchState?.collapsedFiles ?? EMPTY_COLLAPSED_FILES const fileSearchSeedRequestId = searchState?.seedRequestId + const fileSearchFocusRequestId = searchState?.focusRequestId const updateFileSearchState = useAppStore((s) => s.updateFileSearchState) const consumeFileSearchSeedRequest = useAppStore((s) => s.consumeFileSearchSeedRequest) @@ -282,6 +283,13 @@ export default function Search(): React.JSX.Element { scheduleSeededInputSelection ]) + useEffect(() => { + if (!activeWorktreeId || fileSearchFocusRequestId === undefined) { + return + } + inputRef.current?.focus() + }, [activeWorktreeId, fileSearchFocusRequestId]) + const handleClearSearch = useCallback(() => { cancelPendingSearch() clearActiveSearch() @@ -339,7 +347,11 @@ export default function Search(): React.JSX.Element { if (!activeWorktreeId) { return (
- {translate("auto.components.right.sidebar.Search.98c8435e36", "Select a workspace to search")}
+ {translate( + 'auto.components.right.sidebar.Search.98c8435e36', + 'Select a workspace to search' + )} +
) } @@ -385,9 +397,15 @@ export default function Search(): React.JSX.Element { pinned at the top while the user scrolls through results. */} {deferredSearchResults && searchRows.length > 0 && (
- {deferredSearchResults.totalMatches} {translate("auto.components.right.sidebar.Search.6aeda362ed", "result")}{deferredSearchResults.totalMatches !== 1 ? 's' : ''} {translate("auto.components.right.sidebar.Search.4107975b3a", "in")}{' '} - {deferredSearchResults.files.length} {translate("auto.components.right.sidebar.Search.0b8104eaf2", "file")}{deferredSearchResults.files.length !== 1 ? 's' : ''} - {deferredSearchResults.truncated && translate("auto.components.right.sidebar.Search.dcc294f28d", "(results truncated)")} + {deferredSearchResults.totalMatches}{' '} + {translate('auto.components.right.sidebar.Search.6aeda362ed', 'result')} + {deferredSearchResults.totalMatches !== 1 ? 's' : ''}{' '} + {translate('auto.components.right.sidebar.Search.4107975b3a', 'in')}{' '} + {deferredSearchResults.files.length}{' '} + {translate('auto.components.right.sidebar.Search.0b8104eaf2', 'file')} + {deferredSearchResults.files.length !== 1 ? 's' : ''} + {deferredSearchResults.truncated && + translate('auto.components.right.sidebar.Search.dcc294f28d', '(results truncated)')}
)} @@ -435,12 +453,17 @@ export default function Search(): React.JSX.Element { {!fileSearchResults && fileSearchQuery && !fileSearchLoading && (
- {translate("auto.components.right.sidebar.Search.d56d140747", "Press Enter to search")}
+ {translate('auto.components.right.sidebar.Search.d56d140747', 'Press Enter to search')} + )} {!fileSearchQuery && (
- {translate("auto.components.right.sidebar.Search.1abfb25a66", "Type to search in files")}
+ {translate( + 'auto.components.right.sidebar.Search.1abfb25a66', + 'Type to search in files' + )} + )} diff --git a/src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx b/src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx index d6fe74e71..5dd9a9cb5 100644 --- a/src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx +++ b/src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx @@ -1,6 +1,6 @@ import React from 'react' import { MoreHorizontal } from 'lucide-react' -import type { RightSidebarTab } from '@/store/slices/editor' +import type { ActiveRightSidebarTab } from '@/store/slices/editor' import type { CheckStatus } from '../../../../shared/types' import { cn } from '@/lib/utils' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' @@ -15,7 +15,7 @@ import { import { translate } from '@/i18n/i18n' export type ActivityBarItem = { - id: RightSidebarTab + id: ActiveRightSidebarTab icon: React.ComponentType<{ size?: number; className?: string }> title: string shortcut: string @@ -39,8 +39,8 @@ export function TopActivityOverflowMenu({ checksStatus }: { items: ActivityBarItem[] - activeTab: RightSidebarTab - onSelect: (tab: RightSidebarTab) => void + activeTab: ActiveRightSidebarTab + onSelect: (tab: ActiveRightSidebarTab) => void checksStatus?: CheckStatus | null }): React.JSX.Element { const hiddenChecksStatus = diff --git a/src/renderer/src/components/right-sidebar/activity-bar-overflow.test.ts b/src/renderer/src/components/right-sidebar/activity-bar-overflow.test.ts index d556da9ed..0311c3a7a 100644 --- a/src/renderer/src/components/right-sidebar/activity-bar-overflow.test.ts +++ b/src/renderer/src/components/right-sidebar/activity-bar-overflow.test.ts @@ -1,18 +1,17 @@ import { describe, expect, it } from 'vitest' -import type { RightSidebarTab } from '@/store/slices/editor' +import type { ActiveRightSidebarTab } from '@/store/slices/editor' import { getTopActivityBarLayout } from './activity-bar-overflow' -const items = ( - ['explorer', 'search', 'source-control', 'checks', 'ports'] as RightSidebarTab[] -).map((id) => ({ id })) +const items = (['explorer', 'source-control', 'checks', 'ports'] as ActiveRightSidebarTab[]).map( + (id) => ({ id }) +) describe('getTopActivityBarLayout', () => { it('shows every item when the top activity strip has enough room', () => { - const layout = getTopActivityBarLayout(items, 180, 'explorer') + const layout = getTopActivityBarLayout(items, 144, 'explorer') expect(layout.visibleItems.map((item) => item.id)).toEqual([ 'explorer', - 'search', 'source-control', 'checks', 'ports' @@ -21,20 +20,16 @@ describe('getTopActivityBarLayout', () => { }) it('moves trailing items behind the overflow menu when width is tight', () => { - const layout = getTopActivityBarLayout(items, 160, 'explorer') + const layout = getTopActivityBarLayout(items, 124, 'explorer') - expect(layout.visibleItems.map((item) => item.id)).toEqual([ - 'explorer', - 'search', - 'source-control' - ]) + expect(layout.visibleItems.map((item) => item.id)).toEqual(['explorer', 'source-control']) expect(layout.overflowItems.map((item) => item.id)).toEqual(['checks', 'ports']) }) it('keeps the active tab visible even when it would otherwise overflow', () => { - const layout = getTopActivityBarLayout(items, 160, 'ports') + const layout = getTopActivityBarLayout(items, 124, 'ports') - expect(layout.visibleItems.map((item) => item.id)).toEqual(['explorer', 'search', 'ports']) + expect(layout.visibleItems.map((item) => item.id)).toEqual(['explorer', 'ports']) expect(layout.overflowItems.map((item) => item.id)).toEqual(['source-control', 'checks']) }) }) diff --git a/src/renderer/src/components/right-sidebar/activity-bar-overflow.ts b/src/renderer/src/components/right-sidebar/activity-bar-overflow.ts index cdfa0f115..8ace3026c 100644 --- a/src/renderer/src/components/right-sidebar/activity-bar-overflow.ts +++ b/src/renderer/src/components/right-sidebar/activity-bar-overflow.ts @@ -1,12 +1,12 @@ -import type { RightSidebarTab } from '@/store/slices/editor' +import type { ActiveRightSidebarTab } from '@/store/slices/editor' const TOP_ACTIVITY_BUTTON_WIDTH = 36 const TOP_ACTIVITY_MORE_BUTTON_WIDTH = 32 -export function getTopActivityBarLayout( +export function getTopActivityBarLayout( items: readonly T[], availableWidth: number | null, - activeId: RightSidebarTab + activeId: ActiveRightSidebarTab ): { visibleItems: T[]; overflowItems: T[] } { if (!availableWidth || !Number.isFinite(availableWidth)) { return { visibleItems: [...items], overflowItems: [] } diff --git a/src/renderer/src/components/right-sidebar/index.tsx b/src/renderer/src/components/right-sidebar/index.tsx index b1b70848a..fb859f3de 100644 --- a/src/renderer/src/components/right-sidebar/index.tsx +++ b/src/renderer/src/components/right-sidebar/index.tsx @@ -1,6 +1,6 @@ /* eslint-disable max-lines -- Why: the right sidebar owns activity-bar visibility, routing, and resize behavior as one interaction surface; splitting the tab table away would make hidden-tab fallbacks harder to audit. */ import React, { useEffect, useMemo, useState } from 'react' -import { Plug, Files, Search, GitBranch, ListChecks, PanelRight } from 'lucide-react' +import { Plug, Files, GitBranch, ListChecks, PanelRight } from 'lucide-react' import { useAppStore } from '@/store' import { useRepoById } from '@/store/selectors' import { cn } from '@/lib/utils' @@ -37,6 +37,7 @@ import { } from './right-sidebar-width' import { translate } from '@/i18n/i18n' import { RightSidebarPanelContent } from './right-sidebar-panel-content' +import { normalizeRightSidebarRoute } from '@/store/right-sidebar-route' import { AgentSessionHistoryIcon } from './agent-session-history-icon' const ACTIVITY_BAR_SIDE_WIDTH = 40 @@ -45,7 +46,6 @@ const isWindows = typeof navigator !== 'undefined' && navigator.userAgent.includ function RightSidebarInner(): React.JSX.Element { const rightSidebarShortcut = useShortcutLabel('sidebar.right.toggle') const explorerShortcut = useShortcutLabel('sidebar.explorer.toggle') - const searchShortcut = useShortcutLabel('sidebar.search.toggle') const sourceControlShortcut = useShortcutLabel('sidebar.sourceControl.toggle') const checksShortcut = useShortcutLabel('sidebar.checks.toggle') const portsShortcut = useShortcutLabel('sidebar.ports.toggle') @@ -59,6 +59,7 @@ function RightSidebarInner(): React.JSX.Element { const setRightSidebarWidth = useAppStore((s) => s.setRightSidebarWidth) const rightSidebarTab = useAppStore((s) => s.rightSidebarTab) const setRightSidebarTab = useAppStore((s) => s.setRightSidebarTab) + const showRightSidebarFiles = useAppStore((s) => s.showRightSidebarFiles) const toggleRightSidebar = useAppStore((s) => s.toggleRightSidebar) const checksStatus = useAppStore((s) => (s.rightSidebarOpen ? getActiveChecksStatus(s) : null)) const activityBarPosition = useAppStore((s) => s.activityBarPosition) @@ -78,12 +79,6 @@ function RightSidebarInner(): React.JSX.Element { title: translate('auto.components.right.sidebar.index.8bc2bbc3a0', 'Explorer'), shortcut: explorerShortcut === 'Unassigned' ? '' : explorerShortcut }, - { - id: 'search', - icon: Search, - title: translate('auto.components.right.sidebar.index.06219e4cb1', 'Search'), - shortcut: searchShortcut === 'Unassigned' ? '' : searchShortcut - }, { id: 'vault', icon: AgentSessionHistoryIcon, @@ -112,7 +107,7 @@ function RightSidebarInner(): React.JSX.Element { sshOnly: true } ], - [checksShortcut, explorerShortcut, portsShortcut, searchShortcut, sourceControlShortcut] + [checksShortcut, explorerShortcut, portsShortcut, sourceControlShortcut] ) const visibleItems = useMemo( @@ -122,9 +117,17 @@ function RightSidebarInner(): React.JSX.Element { // If the active tab is hidden (e.g. switched from a git repo to a folder), // fall back to the first visible tab. - const effectiveTab = visibleItems.some((item) => item.id === rightSidebarTab) - ? rightSidebarTab + const normalizedActiveTab = normalizeRightSidebarRoute(rightSidebarTab).rightSidebarTab + const effectiveTab = visibleItems.some((item) => item.id === normalizedActiveTab) + ? normalizedActiveTab : visibleItems[0].id + const selectActivityTab = (tab: typeof effectiveTab): void => { + if (tab === 'explorer') { + showRightSidebarFiles() + return + } + setRightSidebarTab(tab) + } const activityBarSideWidth = activityBarPosition === 'side' ? ACTIVITY_BAR_SIDE_WIDTH : 0 const windowWidth = useWindowWidth() @@ -172,7 +175,7 @@ function RightSidebarInner(): React.JSX.Element { key={item.id} item={item} active={effectiveTab === item.id} - onClick={() => setRightSidebarTab(item.id)} + onClick={() => selectActivityTab(item.id)} layout="side" statusIndicator={item.id === 'checks' ? checksStatus : null} /> @@ -249,7 +252,7 @@ function RightSidebarInner(): React.JSX.Element { key={item.id} item={item} active={effectiveTab === item.id} - onClick={() => setRightSidebarTab(item.id)} + onClick={() => selectActivityTab(item.id)} layout="top" statusIndicator={item.id === 'checks' ? checksStatus : null} /> @@ -259,7 +262,7 @@ function RightSidebarInner(): React.JSX.Element { )} @@ -305,7 +308,7 @@ function RightSidebarInner(): React.JSX.Element { key={item.id} item={item} active={effectiveTab === item.id} - onClick={() => setRightSidebarTab(item.id)} + onClick={() => selectActivityTab(item.id)} layout="top" statusIndicator={item.id === 'checks' ? checksStatus : null} /> @@ -315,7 +318,7 @@ function RightSidebarInner(): React.JSX.Element { )} diff --git a/src/renderer/src/components/right-sidebar/right-sidebar-panel-content.tsx b/src/renderer/src/components/right-sidebar/right-sidebar-panel-content.tsx index a3d457ca3..6eff08071 100644 --- a/src/renderer/src/components/right-sidebar/right-sidebar-panel-content.tsx +++ b/src/renderer/src/components/right-sidebar/right-sidebar-panel-content.tsx @@ -1,15 +1,14 @@ import { lazy, Suspense } from 'react' -import type { RightSidebarTab } from '@/store/slices/editor' +import type { ActiveRightSidebarTab } from '@/store/slices/editor' const FileExplorer = lazy(() => import('./FileExplorer')) -const SearchPanel = lazy(() => import('./Search')) const SourceControl = lazy(() => import('./SourceControl')) const ChecksPanel = lazy(() => import('./ChecksPanel')) const PortsPanel = lazy(() => import('./PortsPanel')) const AiVaultPanel = lazy(() => import('./AiVaultPanel')) type RightSidebarPanelContentProps = { - effectiveTab: RightSidebarTab + effectiveTab: ActiveRightSidebarTab rightSidebarOpen: boolean } @@ -21,7 +20,6 @@ export function RightSidebarPanelContent({
{effectiveTab === 'explorer' && } - {effectiveTab === 'search' && } {effectiveTab === 'source-control' && } {effectiveTab === 'checks' && } {/* Why: SSH port forwarding still depends on the raw ports.detect data, diff --git a/src/renderer/src/components/right-sidebar/right-sidebar-titlebar-drag-regions.render.test.tsx b/src/renderer/src/components/right-sidebar/right-sidebar-titlebar-drag-regions.render.test.tsx index 55ce2be1d..c6063cc86 100644 --- a/src/renderer/src/components/right-sidebar/right-sidebar-titlebar-drag-regions.render.test.tsx +++ b/src/renderer/src/components/right-sidebar/right-sidebar-titlebar-drag-regions.render.test.tsx @@ -29,7 +29,9 @@ vi.mock('@/store', () => ({ rightSidebarWidth: 350, setRightSidebarWidth: vi.fn(), rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'files', setRightSidebarTab: vi.fn(), + showRightSidebarFiles: vi.fn(), toggleRightSidebar: vi.fn(), activityBarPosition: mockAppState.activityBarPosition, setActivityBarPosition: vi.fn(), @@ -96,10 +98,6 @@ vi.mock('./SourceControl', () => ({ default: () =>
})) -vi.mock('./Search', () => ({ - default: () =>
-})) - vi.mock('./ChecksPanel', () => ({ default: () =>
})) @@ -146,7 +144,6 @@ describe('rendered right sidebar titlebar drag regions', () => { expect(markup).toContain('right-sidebar-header-drag') expectNoDrag(buttonOpeningTag(markup, 'Explorer')) - expectNoDrag(buttonOpeningTag(markup, 'Search')) expectNoDrag(buttonOpeningTag(markup, 'Source Control')) expectNoDrag(buttonOpeningTag(markup, 'Checks')) expect(buttonOpeningTag(markup, 'Toggle right sidebar')).toContain('sidebar-toggle') @@ -185,7 +182,6 @@ describe('rendered right sidebar titlebar drag regions', () => { expect(sideStrip).toContain('data-context-menu-trigger="true"') expectNoDrag(buttonOpeningTag(markup, 'Explorer')) - expectNoDrag(buttonOpeningTag(markup, 'Search')) expectNoDrag(buttonOpeningTag(markup, 'Source Control')) expectNoDrag(buttonOpeningTag(markup, 'Checks')) expect(buttonOpeningTag(markup, 'Toggle right sidebar')).toContain('sidebar-toggle') @@ -198,7 +194,6 @@ describe('rendered right sidebar titlebar drag regions', () => { expect(markup).not.toContain('data-file-explorer') expect(markup).not.toContain('data-source-control') - expect(markup).not.toContain('data-search-panel') expect(markup).not.toContain('data-checks-panel') expect(markup).not.toContain('data-ports-panel') }) diff --git a/src/renderer/src/components/right-sidebar/useFileExplorerKeys.ts b/src/renderer/src/components/right-sidebar/useFileExplorerKeys.ts index c2105f788..e102afbd4 100644 --- a/src/renderer/src/components/right-sidebar/useFileExplorerKeys.ts +++ b/src/renderer/src/components/right-sidebar/useFileExplorerKeys.ts @@ -43,6 +43,7 @@ export function useFileExplorerKeys(opts: { }): void { const rightSidebarOpen = useAppStore((s) => s.rightSidebarOpen) const rightSidebarTab = useAppStore((s) => s.rightSidebarTab) + const rightSidebarExplorerView = useAppStore((s) => s.rightSidebarExplorerView) const keybindings = useAppStore((s) => s.keybindings) const rowProjectionRef = useRef(opts.rowProjection) @@ -127,7 +128,11 @@ export function useFileExplorerKeys(opts: { } const onKeyDown = (e: KeyboardEvent): void => { - if (!rightSidebarOpen || rightSidebarTab !== 'explorer') { + if ( + !rightSidebarOpen || + rightSidebarTab !== 'explorer' || + rightSidebarExplorerView !== 'files' + ) { return } if (inlineInputRef.current) { @@ -271,5 +276,5 @@ export function useFileExplorerKeys(opts: { window.addEventListener('keydown', onKeyDown, { capture: true }) return () => window.removeEventListener('keydown', onKeyDown, { capture: true }) - }, [keybindings, rightSidebarOpen, rightSidebarTab, opts.containerRef]) + }, [keybindings, rightSidebarExplorerView, rightSidebarOpen, rightSidebarTab, opts.containerRef]) } diff --git a/src/renderer/src/components/right-sidebar/useGitStatusPolling.ts b/src/renderer/src/components/right-sidebar/useGitStatusPolling.ts index 48c30a652..3e5013bc6 100644 --- a/src/renderer/src/components/right-sidebar/useGitStatusPolling.ts +++ b/src/renderer/src/components/right-sidebar/useGitStatusPolling.ts @@ -26,6 +26,7 @@ export function useGitStatusPolling(options: { enabled?: boolean } = {}): void { const sshConnectionStates = useAppStore((s) => s.sshConnectionStates) const rightSidebarOpen = useAppStore((s) => s.rightSidebarOpen) const rightSidebarTab = useAppStore((s) => s.rightSidebarTab) + const rightSidebarExplorerView = useAppStore((s) => s.rightSidebarExplorerView) const openFiles = useAppStore((s) => s.openFiles) const repoMap = useRepoMap() const statusPollInFlightRef = useRef(false) @@ -79,6 +80,7 @@ export function useGitStatusPolling(options: { enabled?: boolean } = {}): void { worktreePath, rightSidebarOpen, rightSidebarTab, + rightSidebarExplorerView, openFiles }) || !activeRepoSupportsGit @@ -115,6 +117,7 @@ export function useGitStatusPolling(options: { enabled?: boolean } = {}): void { fetchUpstreamStatus, isConnectionReady, openFiles, + rightSidebarExplorerView, rightSidebarOpen, rightSidebarTab, worktreePath, diff --git a/src/renderer/src/components/terminal-pane/TerminalPane.tsx b/src/renderer/src/components/terminal-pane/TerminalPane.tsx index 2d6b8dff3..fa7a8502d 100644 --- a/src/renderer/src/components/terminal-pane/TerminalPane.tsx +++ b/src/renderer/src/components/terminal-pane/TerminalPane.tsx @@ -755,15 +755,10 @@ export default function TerminalPane({ [executeClosePane] ) - const handleSearchSelectedText = useCallback( - (selectedText: string): void => { - const state = useAppStore.getState() - state.seedFileSearchQuery(worktreeId, selectedText) - state.setRightSidebarTab('search') - state.setRightSidebarOpen(true) - }, - [worktreeId] - ) + const handleSearchSelectedText = useCallback((selectedText: string): void => { + const state = useAppStore.getState() + state.showRightSidebarSearch({ query: selectedText }) + }, []) const handleConfirmClose = useCallback(() => { if (closeConfirmPaneId === null) { diff --git a/src/renderer/src/hooks/useEditorExternalWatch-targets.test.ts b/src/renderer/src/hooks/useEditorExternalWatch-targets.test.ts index 217015284..68cf34b8b 100644 --- a/src/renderer/src/hooks/useEditorExternalWatch-targets.test.ts +++ b/src/renderer/src/hooks/useEditorExternalWatch-targets.test.ts @@ -58,6 +58,7 @@ describe('getEditorExternalWatchTargets', () => { runtimeEnvironmentId?: string | null rightSidebarOpen?: boolean rightSidebarTab?: EditorExternalWatchTargetState['rightSidebarTab'] + rightSidebarExplorerView?: EditorExternalWatchTargetState['rightSidebarExplorerView'] }): EditorExternalWatchTargetState => ({ openFiles: args.openFiles ?? [], worktreesByRepo: { [args.repo.id]: [args.worktree] }, @@ -65,6 +66,7 @@ describe('getEditorExternalWatchTargets', () => { activeWorktreeId: args.activeWorktreeId ?? null, rightSidebarOpen: args.rightSidebarOpen ?? false, rightSidebarTab: args.rightSidebarTab ?? 'explorer', + rightSidebarExplorerView: args.rightSidebarExplorerView ?? 'files', settings: args.runtimeEnvironmentId === undefined ? null @@ -128,6 +130,24 @@ describe('getEditorExternalWatchTargets', () => { ]) }) + it('does not watch the active worktree while Explorer search is visible', () => { + const repo = makeRepo('repo-active-search') + const worktree = makeWorktree(repo.id, 'wt-active-search') + + expect( + getEditorExternalWatchTargets( + makeState({ + repo, + worktree, + activeWorktreeId: worktree.id, + rightSidebarOpen: true, + rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'search' + }) + ).targets + ).toEqual([]) + }) + it('does not watch the active worktree when a different right sidebar tab is visible', () => { const repo = makeRepo('repo-source-control') const worktree = makeWorktree(repo.id, 'wt-source-control') diff --git a/src/renderer/src/hooks/useEditorExternalWatch.ts b/src/renderer/src/hooks/useEditorExternalWatch.ts index c32d4678c..2606209a3 100644 --- a/src/renderer/src/hooks/useEditorExternalWatch.ts +++ b/src/renderer/src/hooks/useEditorExternalWatch.ts @@ -88,6 +88,7 @@ export type EditorExternalWatchTargetState = Pick< | 'settings' | 'rightSidebarOpen' | 'rightSidebarTab' + | 'rightSidebarExplorerView' > let cachedOpenFiles: AppState['openFiles'] | null = null @@ -97,6 +98,7 @@ let cachedActiveWorktreeId: string | null = null let cachedRuntimeEnvironmentId: string | undefined let cachedRightSidebarOpen: boolean | null = null let cachedRightSidebarTab: AppState['rightSidebarTab'] | null = null +let cachedRightSidebarExplorerView: AppState['rightSidebarExplorerView'] | null = null let cachedWatchedTargetsSnapshot: WatchedTargetsSnapshot = { targets: [], targetsKey: '' } export function getWatchedTargetKey(target: WatchedTarget): string { @@ -121,7 +123,8 @@ export function getEditorExternalWatchTargets( cachedActiveWorktreeId === state.activeWorktreeId && cachedRuntimeEnvironmentId === runtimeEnvironmentId && cachedRightSidebarOpen === state.rightSidebarOpen && - cachedRightSidebarTab === state.rightSidebarTab + cachedRightSidebarTab === state.rightSidebarTab && + cachedRightSidebarExplorerView === state.rightSidebarExplorerView ) { return cachedWatchedTargetsSnapshot } @@ -141,7 +144,12 @@ export function getEditorExternalWatchTargets( // storing the tab, so an ownerless stored tab must stay local here. owners.add(openFileRuntimeOwner(f)) } - if (state.activeWorktreeId && state.rightSidebarOpen && state.rightSidebarTab === 'explorer') { + if ( + state.activeWorktreeId && + state.rightSidebarOpen && + state.rightSidebarTab === 'explorer' && + state.rightSidebarExplorerView === 'files' + ) { // Why: the right sidebar stays mounted while hidden; do not create a // worktree-level watcher just because the user clicked a workspace. // macOS can surface privacy prompts for those passive filesystem probes. @@ -185,6 +193,7 @@ export function getEditorExternalWatchTargets( cachedRuntimeEnvironmentId = runtimeEnvironmentId cachedRightSidebarOpen = state.rightSidebarOpen cachedRightSidebarTab = state.rightSidebarTab + cachedRightSidebarExplorerView = state.rightSidebarExplorerView if (targetsKey === cachedWatchedTargetsSnapshot.targetsKey) { return cachedWatchedTargetsSnapshot diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index 501096f73..b57afc414 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -7511,7 +7511,9 @@ "e041998cad": "Stop generating" }, "FileExplorer": { - "79b1537dd3": "Select a workspace to browse files" + "79b1537dd3": "Select a workspace to browse files", + "4da4d89845": "Back to Explorer", + "6ed5ce817b": "Search" }, "FileExplorerBackgroundMenu": { "3b5e2dcb8d": "New Folder", @@ -7547,7 +7549,8 @@ "78f133232c": "Show Dotfiles", "31b4c3195d": "More Explorer Actions", "d95e30fe28": "Refresh Explorer", - "6026b16950": "Collapse All" + "6026b16950": "Collapse All", + "693cbeadd0": "Search" }, "FileExplorerTreeStatus": { "ce03835e1f": "No files in this workspace", diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.json index 7d3bc12e9..335225ad6 100644 --- a/src/renderer/src/i18n/locales/es.json +++ b/src/renderer/src/i18n/locales/es.json @@ -7511,7 +7511,9 @@ "e041998cad": "dejar de generar" }, "FileExplorer": { - "79b1537dd3": "Seleccione un espacio de trabajo para buscar archivos" + "79b1537dd3": "Seleccione un espacio de trabajo para buscar archivos", + "4da4d89845": "Volver al explorador", + "6ed5ce817b": "Buscar" }, "FileExplorerBackgroundMenu": { "3b5e2dcb8d": "Nueva carpeta", @@ -7547,7 +7549,8 @@ "78f133232c": "Mostrar archivos de puntos", "31b4c3195d": "Más acciones del explorador", "d95e30fe28": "Actualizar explorador", - "6026b16950": "Contraer todo" + "6026b16950": "Contraer todo", + "693cbeadd0": "Buscar" }, "FileExplorerTreeStatus": { "ce03835e1f": "No hay archivos en este espacio de trabajo", diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.json index 8473ae8a5..10345d2dd 100644 --- a/src/renderer/src/i18n/locales/ja.json +++ b/src/renderer/src/i18n/locales/ja.json @@ -7511,7 +7511,9 @@ "e041998cad": "生成を停止する" }, "FileExplorer": { - "79b1537dd3": "ファイルを参照するワークスペースを選択" + "79b1537dd3": "ファイルを参照するワークスペースを選択", + "4da4d89845": "エクスプローラーに戻る", + "6ed5ce817b": "検索" }, "FileExplorerBackgroundMenu": { "3b5e2dcb8d": "新規フォルダー", @@ -7547,7 +7549,8 @@ "78f133232c": "ドットファイルを表示", "31b4c3195d": "エクスプローラーのその他の操作", "d95e30fe28": "エクスプローラーを更新する", - "6026b16950": "すべて折りたたむ" + "6026b16950": "すべて折りたたむ", + "693cbeadd0": "検索" }, "FileExplorerTreeStatus": { "ce03835e1f": "このワークスペースにはファイルがありません", diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.json index c26712c0e..878af6453 100644 --- a/src/renderer/src/i18n/locales/ko.json +++ b/src/renderer/src/i18n/locales/ko.json @@ -7511,7 +7511,9 @@ "e041998cad": "생성 중지" }, "FileExplorer": { - "79b1537dd3": "파일을 찾아보려면 워크스페이스를 선택하세요." + "79b1537dd3": "파일을 찾아보려면 워크스페이스를 선택하세요.", + "4da4d89845": "탐색기로 돌아가기", + "6ed5ce817b": "검색" }, "FileExplorerBackgroundMenu": { "3b5e2dcb8d": "새 폴더", @@ -7547,7 +7549,8 @@ "78f133232c": "도트 파일 표시", "31b4c3195d": "추가 탐색기 작업", "d95e30fe28": "탐색기 새로 고침", - "6026b16950": "모두 축소" + "6026b16950": "모두 축소", + "693cbeadd0": "검색" }, "FileExplorerTreeStatus": { "ce03835e1f": "이 워크스페이스에는 파일이 없습니다.", diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.json index 1e8870e46..9d9ed6079 100644 --- a/src/renderer/src/i18n/locales/zh.json +++ b/src/renderer/src/i18n/locales/zh.json @@ -7511,7 +7511,9 @@ "e041998cad": "停止生成" }, "FileExplorer": { - "79b1537dd3": "选择一个工作区来浏览文件" + "79b1537dd3": "选择一个工作区来浏览文件", + "4da4d89845": "返回资源管理器", + "6ed5ce817b": "搜索" }, "FileExplorerBackgroundMenu": { "3b5e2dcb8d": "新建文件夹", @@ -7547,7 +7549,8 @@ "78f133232c": "显示点文件", "31b4c3195d": "更多资源管理器操作", "d95e30fe28": "刷新资源管理器", - "6026b16950": "全部折叠" + "6026b16950": "全部折叠", + "693cbeadd0": "搜索" }, "FileExplorerTreeStatus": { "ce03835e1f": "此工作区中没有文件", diff --git a/src/renderer/src/lib/passive-macos-app-data-access.test.ts b/src/renderer/src/lib/passive-macos-app-data-access.test.ts index 59e110a69..953bd2c5e 100644 --- a/src/renderer/src/lib/passive-macos-app-data-access.test.ts +++ b/src/renderer/src/lib/passive-macos-app-data-access.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' import { isMacAppDataPath, shouldPollActiveGitStatus } from './passive-macos-app-data-access' -import type { OpenFile, RightSidebarTab } from '@/store/slices/editor' +import type { ActiveRightSidebarTab, OpenFile } from '@/store/slices/editor' const MAC = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)' const LINUX = 'Mozilla/5.0 (X11; Linux x86_64)' @@ -12,7 +12,8 @@ function pollArgs( activeWorktreeId: 'wt-1', worktreePath: '/Users/me/Library/Containers/com.apple.TextEdit/Data/Documents/repo', rightSidebarOpen: false, - rightSidebarTab: 'explorer' as RightSidebarTab, + rightSidebarTab: 'explorer' as ActiveRightSidebarTab, + rightSidebarExplorerView: 'files', openFiles: [], userAgent: MAC, ...overrides @@ -43,6 +44,18 @@ describe('shouldPollActiveGitStatus', () => { ).toBe(true) }) + it('does not treat Explorer search as a file-tree visibility signal', () => { + expect( + shouldPollActiveGitStatus( + pollArgs({ + rightSidebarOpen: true, + rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'search' + }) + ) + ).toBe(false) + }) + it('allows polling when an editor file is open in the worktree', () => { const openFile: OpenFile = { id: 'file-1', diff --git a/src/renderer/src/lib/passive-macos-app-data-access.ts b/src/renderer/src/lib/passive-macos-app-data-access.ts index 137dbfa00..5475adbc1 100644 --- a/src/renderer/src/lib/passive-macos-app-data-access.ts +++ b/src/renderer/src/lib/passive-macos-app-data-access.ts @@ -1,4 +1,8 @@ -import type { OpenFile, RightSidebarTab } from '@/store/slices/editor' +import type { + ActiveRightSidebarTab, + OpenFile, + RightSidebarExplorerView +} from '@/store/slices/editor' const MAC_APP_DATA_SEGMENT_RE = /(^|\/)Library\/(Containers|Group Containers)\// @@ -20,7 +24,8 @@ export function shouldPollActiveGitStatus(args: { activeWorktreeId: string | null worktreePath: string | null rightSidebarOpen: boolean - rightSidebarTab: RightSidebarTab + rightSidebarTab: ActiveRightSidebarTab + rightSidebarExplorerView?: RightSidebarExplorerView openFiles?: OpenFile[] userAgent?: string }): boolean { @@ -30,7 +35,7 @@ export function shouldPollActiveGitStatus(args: { if ( args.rightSidebarOpen && (args.rightSidebarTab === 'source-control' || - args.rightSidebarTab === 'explorer' || + (args.rightSidebarTab === 'explorer' && args.rightSidebarExplorerView !== 'search') || args.rightSidebarTab === 'checks') ) { return true diff --git a/src/renderer/src/lib/startup-ui-hydration.ts b/src/renderer/src/lib/startup-ui-hydration.ts index 8735e305c..9467211db 100644 --- a/src/renderer/src/lib/startup-ui-hydration.ts +++ b/src/renderer/src/lib/startup-ui-hydration.ts @@ -37,6 +37,7 @@ export function getStartupErrorFallbackUI(uiHydrated: boolean): PersistedUIState sidebarWidth: 280, rightSidebarOpen: true, rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'files', rightSidebarWidth: 350, groupBy: 'repo', sortBy: 'name', diff --git a/src/renderer/src/store/right-sidebar-route.ts b/src/renderer/src/store/right-sidebar-route.ts new file mode 100644 index 000000000..c252e285d --- /dev/null +++ b/src/renderer/src/store/right-sidebar-route.ts @@ -0,0 +1,34 @@ +import type { ActiveRightSidebarTab, RightSidebarExplorerView } from '../../../shared/types' + +export type RightSidebarRoute = { + rightSidebarTab: ActiveRightSidebarTab + rightSidebarExplorerView: RightSidebarExplorerView +} + +function normalizeRightSidebarExplorerView(view: unknown): RightSidebarExplorerView { + return view === 'search' ? 'search' : 'files' +} + +export function normalizeRightSidebarRoute( + tab: unknown, + explorerView?: unknown +): RightSidebarRoute { + // Why: older builds persisted Search as a standalone activity tab. + if (tab === 'search') { + return { rightSidebarTab: 'explorer', rightSidebarExplorerView: 'search' } + } + if ( + tab === 'explorer' || + tab === 'vault' || + tab === 'source-control' || + tab === 'checks' || + tab === 'ports' + ) { + return { + rightSidebarTab: tab, + rightSidebarExplorerView: + tab === 'explorer' ? normalizeRightSidebarExplorerView(explorerView) : 'files' + } + } + return { rightSidebarTab: 'explorer', rightSidebarExplorerView: 'files' } +} diff --git a/src/renderer/src/store/slices/editor.test.ts b/src/renderer/src/store/slices/editor.test.ts index 03b87fd3b..2d5f96a13 100644 --- a/src/renderer/src/store/slices/editor.test.ts +++ b/src/renderer/src/store/slices/editor.test.ts @@ -114,9 +114,9 @@ describe('createEditorSlice right sidebar state', () => { it('setRightSidebarTab updates the global tab without writing a worktree entry', () => { const store = createEditorStore() - store.getState().setRightSidebarTab('search') + store.getState().setRightSidebarTab('checks') - expect(store.getState().rightSidebarTab).toBe('search') + expect(store.getState().rightSidebarTab).toBe('checks') expect(store.getState().rightSidebarTabByWorktree).toEqual({}) }) @@ -125,18 +125,97 @@ describe('createEditorSlice right sidebar state', () => { const remembered = { 'wt-1': 'checks' as const } store.setState({ activeWorktreeId: null, rightSidebarTabByWorktree: remembered }) - store.getState().setRightSidebarTab('search') + store.getState().setRightSidebarTab('checks') - expect(store.getState().rightSidebarTab).toBe('search') + expect(store.getState().rightSidebarTab).toBe('checks') expect(store.getState().rightSidebarTabByWorktree).toBe(remembered) }) + it('showRightSidebarFiles opens Explorer files', () => { + const store = createEditorStore() + store.setState({ rightSidebarOpen: false, rightSidebarTab: 'checks' }) + + store.getState().showRightSidebarFiles() + + expect(store.getState().rightSidebarOpen).toBe(true) + expect(store.getState().rightSidebarTab).toBe('explorer') + expect(store.getState().rightSidebarExplorerView).toBe('files') + expect(store.getState().rightSidebarExplorerViewByWorktree).toEqual({ 'wt-1': 'files' }) + }) + + it('showRightSidebarSearch opens Explorer search and requests focus without payload', () => { + const store = createEditorStore() + store.getState().updateFileSearchState('wt-1', { + query: 'needle', + results: { files: [], totalMatches: 1, truncated: false } + }) + + store.getState().showRightSidebarSearch() + + expect(store.getState().rightSidebarOpen).toBe(true) + expect(store.getState().rightSidebarTab).toBe('explorer') + expect(store.getState().rightSidebarExplorerView).toBe('search') + expect(store.getState().rightSidebarExplorerViewByWorktree).toEqual({ 'wt-1': 'search' }) + expect(store.getState().fileSearchStateByWorktree['wt-1']).toMatchObject({ + query: 'needle', + results: { files: [], totalMatches: 1, truncated: false }, + focusRequestId: 1 + }) + expect(store.getState().fileSearchStateByWorktree['wt-1']?.seedRequestId).toBeUndefined() + }) + + it('showRightSidebarSearch seeds query and include together with one request', () => { + const store = createEditorStore() + + store.getState().showRightSidebarSearch({ query: 'needle', includePattern: 'src/**' }) + + expect(store.getState().fileSearchStateByWorktree['wt-1']).toMatchObject({ + query: 'needle', + includePattern: 'src/**', + results: null, + loading: false, + seedRequestId: 1 + }) + }) + + it('showRightSidebarSearch include-only focuses when the query is empty', () => { + const store = createEditorStore() + + store.getState().showRightSidebarSearch({ includePattern: 'src/**' }) + + expect(store.getState().fileSearchStateByWorktree['wt-1']).toMatchObject({ + query: '', + includePattern: 'src/**', + focusRequestId: 1 + }) + expect(store.getState().fileSearchStateByWorktree['wt-1']?.seedRequestId).toBeUndefined() + }) + + it('showRightSidebarSearch include-only reruns an existing query', () => { + const store = createEditorStore() + store.getState().updateFileSearchState('wt-1', { + query: 'needle', + results: { files: [], totalMatches: 1, truncated: false } + }) + + store.getState().showRightSidebarSearch({ includePattern: 'src/**' }) + + expect(store.getState().fileSearchStateByWorktree['wt-1']).toMatchObject({ + query: 'needle', + includePattern: 'src/**', + results: null, + loading: false, + seedRequestId: 1 + }) + }) + it('revealInExplorer selects explorer globally without writing a worktree entry', () => { const store = createEditorStore() - const remembered = { 'wt-1': 'search' as const, 'wt-2': 'checks' as const } + const remembered = { 'wt-1': 'explorer' as const, 'wt-2': 'checks' as const } store.setState({ activeWorktreeId: 'wt-1', - rightSidebarTab: 'search', + rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'search', rightSidebarTabByWorktree: remembered }) @@ -144,6 +223,8 @@ describe('createEditorSlice right sidebar state', () => { expect(store.getState().rightSidebarOpen).toBe(true) expect(store.getState().rightSidebarTab).toBe('explorer') + expect(store.getState().rightSidebarExplorerView).toBe('files') + expect(store.getState().rightSidebarExplorerViewByWorktree).toEqual({ 'wt-2': 'files' }) expect(store.getState().rightSidebarTabByWorktree).toBe(remembered) expect(store.getState().pendingExplorerReveal).toMatchObject({ worktreeId: 'wt-2', diff --git a/src/renderer/src/store/slices/editor.ts b/src/renderer/src/store/slices/editor.ts index 8a70a8477..98a0b0444 100644 --- a/src/renderer/src/store/slices/editor.ts +++ b/src/renderer/src/store/slices/editor.ts @@ -23,7 +23,8 @@ import type { Tab, TabGroup, GitUpstreamStatus, - RightSidebarTab, + ActiveRightSidebarTab, + RightSidebarExplorerView, SearchResult, WorkspaceSessionState, WorkspaceVisibleTabType @@ -51,7 +52,30 @@ import { createUntitledMarkdownFileWithTemplateSelection } from '@/lib/create-un import { extractIpcErrorMessage } from '@/lib/ipc-error' import { translate } from '@/i18n/i18n' -export type { RightSidebarTab } from '../../../../shared/types' +export type { + ActiveRightSidebarTab, + RightSidebarExplorerView, + RightSidebarTab +} from '../../../../shared/types' + +const DEFAULT_FILE_SEARCH_STATE = { + query: '', + caseSensitive: false, + wholeWord: false, + useRegex: false, + includePattern: '', + excludePattern: '', + results: null, + loading: false, + collapsedFiles: new Set() +} satisfies Omit< + EditorSlice['fileSearchStateByWorktree'][string], + 'seedRequestId' | 'focusRequestId' +> + +function defaultFileSearchState(): EditorSlice['fileSearchStateByWorktree'][string] { + return { ...DEFAULT_FILE_SEARCH_STATE, collapsedFiles: new Set() } +} export type DiffSource = | 'unstaged' @@ -303,13 +327,21 @@ export type EditorSlice = { // Right sidebar rightSidebarOpen: boolean rightSidebarWidth: number - rightSidebarTab: RightSidebarTab - rightSidebarTabByWorktree: Record + rightSidebarTab: ActiveRightSidebarTab + rightSidebarExplorerView: RightSidebarExplorerView + rightSidebarTabByWorktree: Record + rightSidebarExplorerViewByWorktree: Record activityBarPosition: ActivityBarPosition toggleRightSidebar: () => void setRightSidebarOpen: (open: boolean) => void setRightSidebarWidth: (width: number) => void - setRightSidebarTab: (tab: RightSidebarTab) => void + setRightSidebarTab: (tab: ActiveRightSidebarTab) => void + setRightSidebarExplorerView: (view: RightSidebarExplorerView) => void + showRightSidebarFiles: () => void + showRightSidebarSearch: (payload?: { + query?: string | null + includePattern?: string | null + }) => void setActivityBarPosition: (position: ActivityBarPosition) => void // File explorer state @@ -541,6 +573,7 @@ export type EditorSlice = { loading: boolean collapsedFiles: Set seedRequestId?: number + focusRequestId?: number } > updateFileSearchState: ( @@ -1364,12 +1397,91 @@ export const createEditorSlice: StateCreator = (s rightSidebarOpen: false, rightSidebarWidth: 280, rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'files', rightSidebarTabByWorktree: {}, + rightSidebarExplorerViewByWorktree: {}, activityBarPosition: 'top', toggleRightSidebar: () => set((s) => ({ rightSidebarOpen: !s.rightSidebarOpen })), setRightSidebarOpen: (open) => set({ rightSidebarOpen: open }), setRightSidebarWidth: (width) => set({ rightSidebarWidth: width }), - setRightSidebarTab: (tab) => set({ rightSidebarTab: tab }), + setRightSidebarTab: (tab) => + set({ + rightSidebarTab: tab, + ...(tab === 'explorer' ? { rightSidebarExplorerView: 'files' as const } : {}) + }), + setRightSidebarExplorerView: (view) => + set((s) => ({ + rightSidebarExplorerView: view, + ...(s.activeWorktreeId + ? { + rightSidebarExplorerViewByWorktree: { + ...s.rightSidebarExplorerViewByWorktree, + [s.activeWorktreeId]: view + } + } + : {}) + })), + showRightSidebarFiles: () => + set((s) => ({ + rightSidebarOpen: true, + rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'files', + ...(s.activeWorktreeId + ? { + rightSidebarExplorerViewByWorktree: { + ...s.rightSidebarExplorerViewByWorktree, + [s.activeWorktreeId]: 'files' + } + } + : {}) + })), + showRightSidebarSearch: (payload) => + set((s) => { + const next = { + rightSidebarOpen: true, + rightSidebarTab: 'explorer' as const, + rightSidebarExplorerView: 'search' as const, + ...(s.activeWorktreeId + ? { + rightSidebarExplorerViewByWorktree: { + ...s.rightSidebarExplorerViewByWorktree, + [s.activeWorktreeId]: 'search' as const + } + } + : {}) + } + if (!s.activeWorktreeId) { + return next + } + + const query = payload?.query?.trim() ? payload.query : null + const includePattern = payload?.includePattern?.trim() ? payload.includePattern : null + const current = s.fileSearchStateByWorktree[s.activeWorktreeId] || defaultFileSearchState() + const shouldSeed = Boolean(query || (includePattern && current.query.trim())) + const shouldFocus = !shouldSeed + const nextSearchState = { + ...current, + ...(query ? { query } : {}), + ...(includePattern ? { includePattern } : {}), + ...(shouldSeed + ? { + results: null, + loading: false, + collapsedFiles: new Set(), + seedRequestId: (current.seedRequestId ?? 0) + 1 + } + : {}), + ...(shouldFocus ? { focusRequestId: (current.focusRequestId ?? 0) + 1 } : {}) + } + + return { + ...next, + fileSearchStateByWorktree: { + ...s.fileSearchStateByWorktree, + [s.activeWorktreeId]: nextSearchState + } + } + }), setActivityBarPosition: (position) => set({ activityBarPosition: position }), // File explorer @@ -1414,11 +1526,16 @@ export const createEditorSlice: StateCreator = (s }), pendingExplorerReveal: null, revealInExplorer: (worktreeId, filePath) => - set({ + set((s) => ({ rightSidebarOpen: true, rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'files', + rightSidebarExplorerViewByWorktree: { + ...s.rightSidebarExplorerViewByWorktree, + [worktreeId]: 'files' + }, pendingExplorerReveal: { worktreeId, filePath, requestId: Date.now() } - }), + })), clearPendingExplorerReveal: () => set({ pendingExplorerReveal: null }), // Open files @@ -3503,17 +3620,7 @@ export const createEditorSlice: StateCreator = (s fileSearchStateByWorktree: {}, updateFileSearchState: (worktreeId, updates) => set((s) => { - const current = s.fileSearchStateByWorktree[worktreeId] || { - query: '', - caseSensitive: false, - wholeWord: false, - useRegex: false, - includePattern: '', - excludePattern: '', - results: null, - loading: false, - collapsedFiles: new Set() - } + const current = s.fileSearchStateByWorktree[worktreeId] || defaultFileSearchState() return { fileSearchStateByWorktree: { ...s.fileSearchStateByWorktree, @@ -3523,17 +3630,7 @@ export const createEditorSlice: StateCreator = (s }), seedFileSearchQuery: (worktreeId, query) => set((s) => { - const current = s.fileSearchStateByWorktree[worktreeId] || { - query: '', - caseSensitive: false, - wholeWord: false, - useRegex: false, - includePattern: '', - excludePattern: '', - results: null, - loading: false, - collapsedFiles: new Set() - } + const current = s.fileSearchStateByWorktree[worktreeId] || defaultFileSearchState() return { fileSearchStateByWorktree: { ...s.fileSearchStateByWorktree, @@ -3550,17 +3647,7 @@ export const createEditorSlice: StateCreator = (s }), seedFileSearchIncludePattern: (worktreeId, includePattern) => set((s) => { - const current = s.fileSearchStateByWorktree[worktreeId] || { - query: '', - caseSensitive: false, - wholeWord: false, - useRegex: false, - includePattern: '', - excludePattern: '', - results: null, - loading: false, - collapsedFiles: new Set() - } + const current = s.fileSearchStateByWorktree[worktreeId] || defaultFileSearchState() return { fileSearchStateByWorktree: { ...s.fileSearchStateByWorktree, diff --git a/src/renderer/src/store/slices/store-cascades.test.ts b/src/renderer/src/store/slices/store-cascades.test.ts index cc9253e33..7373d4b95 100644 --- a/src/renderer/src/store/slices/store-cascades.test.ts +++ b/src/renderer/src/store/slices/store-cascades.test.ts @@ -137,7 +137,8 @@ describe('removeWorktree cascade', () => { activeFileId: '/path/wt1/file.ts', activeTabType: 'editor', activeFileIdByWorktree: { [worktreeId]: '/path/wt1/file.ts' }, - activeTabTypeByWorktree: { [worktreeId]: 'editor' } + activeTabTypeByWorktree: { [worktreeId]: 'editor' }, + rightSidebarExplorerViewByWorktree: { [worktreeId]: 'search' } }) const result = await store.getState().removeWorktree(worktreeId) @@ -159,6 +160,7 @@ describe('removeWorktree cascade', () => { expect(s.activeTabType).toBe('terminal') expect(s.activeFileIdByWorktree[worktreeId]).toBeUndefined() expect(s.activeTabTypeByWorktree[worktreeId]).toBeUndefined() + expect(s.rightSidebarExplorerViewByWorktree[worktreeId]).toBeUndefined() }) it('warns when workspace removal keeps the local branch', async () => { @@ -759,7 +761,7 @@ describe('setActiveWorktree', () => { ] }, rightSidebarTab: 'checks', - rightSidebarTabByWorktree: { [wt1]: 'search', [wt2]: 'explorer' } + rightSidebarTabByWorktree: { [wt1]: 'search' as never, [wt2]: 'explorer' } }) store.getState().setActiveWorktree(wt1) @@ -772,6 +774,41 @@ describe('setActiveWorktree', () => { expect(store.getState().rightSidebarTab).toBe('checks') }) + it('restores the Explorer files/search subview per worktree when switching', () => { + const store = createTestStore() + const wt1 = 'repo1::/path/wt1' + const wt2 = 'repo1::/path/wt2' + const wt3 = 'repo1::/path/wt3' + + seedStore(store, { + worktreesByRepo: { + repo1: [ + makeWorktree({ id: wt1, repoId: 'repo1', path: '/path/wt1' }), + makeWorktree({ id: wt2, repoId: 'repo1', path: '/path/wt2' }), + makeWorktree({ id: wt3, repoId: 'repo1', path: '/path/wt3' }) + ] + }, + rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'search', + rightSidebarExplorerViewByWorktree: { + [wt1]: 'search', + [wt2]: 'files' + } + }) + + store.getState().setActiveWorktree(wt1) + expect(store.getState().rightSidebarExplorerView).toBe('search') + + store.getState().setActiveWorktree(wt2) + expect(store.getState().rightSidebarExplorerView).toBe('files') + + store.getState().setActiveWorktree(wt3) + expect(store.getState().rightSidebarExplorerView).toBe('files') + + store.getState().setActiveWorktree(wt1) + expect(store.getState().rightSidebarExplorerView).toBe('search') + }) + it('does not reset the right sidebar tab for worktrees without remembered sidebar state', () => { const store = createTestStore() const wt = 'repo1::/path/wt1' @@ -851,7 +888,7 @@ describe('setActiveWorktree', () => { seedStore(store, { activeWorktreeId: 'repo1::/path/wt1', rightSidebarTab: 'checks', - rightSidebarTabByWorktree: { 'repo1::/path/wt1': 'search' } + rightSidebarTabByWorktree: { 'repo1::/path/wt1': 'search' as never } }) store.getState().setActiveWorktree(null) diff --git a/src/renderer/src/store/slices/ui.test.ts b/src/renderer/src/store/slices/ui.test.ts index a73d610e5..a8f4e8fbc 100644 --- a/src/renderer/src/store/slices/ui.test.ts +++ b/src/renderer/src/store/slices/ui.test.ts @@ -67,6 +67,8 @@ function createUIStore(): StoreApi { worktreesByRepo: {}, rightSidebarOpen: false, rightSidebarWidth: 280, + rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'files', ...createSettingsSearchState(args[0]), ...createWorktreeNavHistorySlice(...(args as Parameters)), ...createUISlice(...(args as Parameters)) @@ -614,6 +616,29 @@ describe('createUISlice hydratePersistedUI', () => { store.getState().hydratePersistedUI(makePersistedUI({ rightSidebarTab: 'checks' })) expect(store.getState().rightSidebarTab).toBe('checks') + expect(store.getState().rightSidebarExplorerView).toBe('files') + }) + + it('hydrates legacy persisted search tab as Explorer search', () => { + const store = createUIStore() + + store.getState().hydratePersistedUI(makePersistedUI({ rightSidebarTab: 'search' })) + + expect(store.getState().rightSidebarTab).toBe('explorer') + expect(store.getState().rightSidebarExplorerView).toBe('search') + }) + + it('hydrates persisted Explorer search view', () => { + const store = createUIStore() + + store + .getState() + .hydratePersistedUI( + makePersistedUI({ rightSidebarTab: 'explorer', rightSidebarExplorerView: 'search' }) + ) + + expect(store.getState().rightSidebarTab).toBe('explorer') + expect(store.getState().rightSidebarExplorerView).toBe('search') }) it('hydrates persisted per-worktree dotfile visibility', () => { @@ -680,6 +705,7 @@ describe('createUISlice hydratePersistedUI', () => { ) expect(store.getState().rightSidebarTab).toBe('explorer') + expect(store.getState().rightSidebarExplorerView).toBe('files') }) it('clamps persisted sidebar widths into the supported range', () => { diff --git a/src/renderer/src/store/slices/ui.ts b/src/renderer/src/store/slices/ui.ts index 14d5dbcc6..42c2d4ae1 100644 --- a/src/renderer/src/store/slices/ui.ts +++ b/src/renderer/src/store/slices/ui.ts @@ -1,6 +1,7 @@ /* eslint-disable max-lines */ import type { StateCreator } from 'zustand' import type { AppState } from '../types' +import { normalizeRightSidebarRoute } from '../right-sidebar-route' import { findPrevLiveNonTaskStackHistoryIndex, findPrevLiveWorktreeHistoryIndex @@ -242,22 +243,6 @@ function migrateStatusBarItems(items: readonly string[] | undefined): StatusBarI const DEFAULT_ON_PORTS_STATUS_BAR_ITEM: StatusBarItem = 'ports' const DEFAULT_ON_KIMI_STATUS_BAR_ITEM: StatusBarItem = 'kimi' -function normalizePersistedRightSidebarTab( - tab: PersistedUIState['rightSidebarTab'] | unknown -): PersistedUIState['rightSidebarTab'] { - if ( - tab === 'explorer' || - tab === 'search' || - tab === 'vault' || - tab === 'source-control' || - tab === 'checks' || - tab === 'ports' - ) { - return tab - } - return 'explorer' -} - const MIN_SIDEBAR_WIDTH = 220 const MAX_LEFT_SIDEBAR_WIDTH = 500 // Why: the right sidebar drag-resize is window-relative (see right-sidebar @@ -1979,6 +1964,10 @@ export const createUISlice: StateCreator = (set, get) }) .catch(console.error) } + const rightSidebarRoute = normalizeRightSidebarRoute( + ui.rightSidebarTab, + ui.rightSidebarExplorerView + ) return { // Why: persisted UI data comes from disk and may be stale, corrupted, // or manually edited. Clamp widths during hydration so invalid values @@ -1995,7 +1984,8 @@ export const createUISlice: StateCreator = (set, get) MAX_RIGHT_SIDEBAR_WIDTH ), rightSidebarOpen: typeof ui.rightSidebarOpen === 'boolean' ? ui.rightSidebarOpen : true, - rightSidebarTab: normalizePersistedRightSidebarTab(ui.rightSidebarTab), + rightSidebarTab: rightSidebarRoute.rightSidebarTab, + rightSidebarExplorerView: rightSidebarRoute.rightSidebarExplorerView, groupBy: (ui.groupBy as UISlice['groupBy'] | 'parent') === 'parent' ? 'repo' : ui.groupBy, sortBy, // Why: main-process getUI() already normalized this to a valid value diff --git a/src/renderer/src/store/slices/worktrees.test.ts b/src/renderer/src/store/slices/worktrees.test.ts index dee5732ef..941bc50d3 100644 --- a/src/renderer/src/store/slices/worktrees.test.ts +++ b/src/renderer/src/store/slices/worktrees.test.ts @@ -422,8 +422,12 @@ describe('fetchWorktrees', () => { worktreesByRepo: { repo1: [removed, surviving] }, sortEpoch: 7, rightSidebarTabByWorktree: { - [removed.id]: 'search', + [removed.id]: 'search' as never, [surviving.id]: 'checks' + }, + rightSidebarExplorerViewByWorktree: { + [removed.id]: 'search', + [surviving.id]: 'files' } } as Partial) @@ -431,6 +435,9 @@ describe('fetchWorktrees', () => { expect(store.getState().worktreesByRepo.repo1).toEqual([surviving]) expect(store.getState().rightSidebarTabByWorktree).toEqual({ [surviving.id]: 'checks' }) + expect(store.getState().rightSidebarExplorerViewByWorktree).toEqual({ + [surviving.id]: 'files' + }) expect(store.getState().sortEpoch).toBe(8) }) @@ -459,6 +466,10 @@ describe('fetchWorktrees', () => { sortEpoch: 7, rightSidebarTabByWorktree: { [visible.id]: 'checks', + [hidden.id]: 'search' as never + }, + rightSidebarExplorerViewByWorktree: { + [visible.id]: 'files', [hidden.id]: 'search' }, tabsByWorktree: { @@ -470,6 +481,7 @@ describe('fetchWorktrees', () => { expect(store.getState().worktreesByRepo.repo1).toEqual([visible]) expect(store.getState().rightSidebarTabByWorktree).toEqual({ [visible.id]: 'checks' }) + expect(store.getState().rightSidebarExplorerViewByWorktree).toEqual({ [visible.id]: 'files' }) expect(store.getState().tabsByWorktree[hidden.id]).toBeUndefined() expect(store.getState().sortEpoch).toBe(7) }) @@ -546,7 +558,7 @@ describe('fetchWorktrees', () => { worktreesByRepo: { repo1: [missingFromFallback, fallback] }, sortEpoch: 7, rightSidebarTabByWorktree: { - [missingFromFallback.id]: 'search', + [missingFromFallback.id]: 'search' as never, [fallback.id]: 'checks' }, tabsByWorktree: { @@ -581,7 +593,7 @@ describe('fetchWorktrees', () => { store.setState({ worktreesByRepo: { repo1: [existing] }, sortEpoch: 7, - rightSidebarTabByWorktree: { [existing.id]: 'search' } + rightSidebarTabByWorktree: { [existing.id]: 'search' as never } } as Partial) const result = await store.getState().fetchWorktrees('repo1') @@ -3289,7 +3301,7 @@ describe('purgeWorktreeTerminalState direct (design §4.4)', () => { 'repoA::/a/wt2': ['coverage/'] }, rightSidebarTabByWorktree: { - 'repoA::/a/wt1': 'search', + 'repoA::/a/wt1': 'search' as never, 'repoA::/a/wt2': 'checks' }, activeWorktreeId: 'repoA::/a/wt1', diff --git a/src/renderer/src/store/slices/worktrees.ts b/src/renderer/src/store/slices/worktrees.ts index 55a8397e6..c50416597 100644 --- a/src/renderer/src/store/slices/worktrees.ts +++ b/src/renderer/src/store/slices/worktrees.ts @@ -611,6 +611,25 @@ function buildWorktreePurgeState(s: AppState, worktreeIds: string[]): Partial { + const omitted = omitByWorktree(s.rightSidebarTabByWorktree) + let changed = omitted !== s.rightSidebarTabByWorktree + const out: AppState['rightSidebarTabByWorktree'] = {} + for (const [id, tab] of Object.entries(omitted)) { + if ( + tab === 'explorer' || + tab === 'vault' || + tab === 'source-control' || + tab === 'checks' || + tab === 'ports' + ) { + out[id] = tab + } else { + changed = true + } + } + return changed ? out : omitted + } const omitByTabId = (obj: Record): Record => { let changed = false const out = { ...obj } @@ -683,7 +702,8 @@ function buildWorktreePurgeState(s: AppState, worktreeIds: string[]): Partial delete nextExpandedDirs[worktreeId] const nextShowDotfilesByWorktree = { ...s.showDotfilesByWorktree } delete nextShowDotfilesByWorktree[worktreeId] + const nextRightSidebarExplorerViewByWorktree = { + ...s.rightSidebarExplorerViewByWorktree + } + delete nextRightSidebarExplorerViewByWorktree[worktreeId] // If the active file belonged to the removed worktree, clear it const activeFileCleared = s.activeFileId ? s.openFiles.some((f) => f.id === s.activeFileId && f.worktreeId === worktreeId) @@ -1499,6 +1523,7 @@ export const createWorktreeSlice: StateCreator activeFileIdByWorktree: nextActiveFileIdByWorktree, activeBrowserTabIdByWorktree: nextActiveBrowserTabIdByWorktree, activeTabTypeByWorktree: nextActiveTabTypeByWorktree, + rightSidebarExplorerViewByWorktree: nextRightSidebarExplorerViewByWorktree, activeTabIdByWorktree: nextActiveTabIdByWorktree, tabBarOrderByWorktree: nextTabBarOrderByWorktree, pendingReconnectTabByWorktree: nextPendingReconnectTabByWorktree, @@ -2185,6 +2210,10 @@ export const createWorktreeSlice: StateCreator shouldClearUnread = Boolean(worktree?.isUnread) // Restore per-worktree editor state + // Why: Search now lives under Explorer, so the files/search sub-route + // must switch with the worktree instead of leaking the previous one. + const restoredRightSidebarExplorerView = + s.rightSidebarExplorerViewByWorktree?.[worktreeId] ?? 'files' const restoredFileId = s.activeFileIdByWorktree[worktreeId] ?? null const restoredBrowserTabId = s.activeBrowserTabIdByWorktree[worktreeId] ?? null const restoredTabType = s.activeTabTypeByWorktree[worktreeId] ?? 'terminal' @@ -2376,6 +2405,7 @@ export const createWorktreeSlice: StateCreator s.activeFileId !== activeFileId || s.activeBrowserTabId !== activeBrowserTabId || s.activeTabType !== activeTabType || + s.rightSidebarExplorerView !== restoredRightSidebarExplorerView || s.activeTabId !== activeTabId || nextActiveTabTypeByWorktree !== s.activeTabTypeByWorktree || nextEverActivated !== s.everActivatedWorktreeIds || @@ -2395,6 +2425,7 @@ export const createWorktreeSlice: StateCreator activeBrowserTabId, activeTabType, activeTabTypeByWorktree: nextActiveTabTypeByWorktree, + rightSidebarExplorerView: restoredRightSidebarExplorerView, activeTabId, everActivatedWorktreeIds: nextEverActivated, ...(nextWorktrees !== s.worktreesByRepo ? { worktreesByRepo: nextWorktrees } : {}), diff --git a/src/shared/constants.ts b/src/shared/constants.ts index d308aa4e9..f744a92b2 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -407,6 +407,7 @@ export function getDefaultUIState(): PersistedUIState { sidebarWidth: 280, rightSidebarOpen: true, rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'files', rightSidebarWidth: 350, groupBy: 'repo', sortBy: 'recent', diff --git a/src/shared/types.ts b/src/shared/types.ts index 581aa384b..f50b39f63 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -2616,6 +2616,8 @@ export type RightSidebarTab = | 'source-control' | 'checks' | 'ports' +export type ActiveRightSidebarTab = Exclude +export type RightSidebarExplorerView = 'files' | 'search' export type ProjectOrderBy = 'manual' | 'recent' @@ -2625,6 +2627,7 @@ export type PersistedUIState = { sidebarWidth: number rightSidebarOpen: boolean rightSidebarTab: RightSidebarTab + rightSidebarExplorerView: RightSidebarExplorerView rightSidebarWidth: number groupBy: 'none' | 'workspace-status' | 'repo' | 'pr-status' sortBy: 'name' | 'smart' | 'recent' | 'repo' | 'manual'