Combine file search and file explorer right sidebar tabs (#5182)

Unifies file discovery and tree navigation under a single Explorer domain, simplifying the right sidebar activity bar and reducing tab clutter.

* Replaces the standalone 'search' activity bar tab with a nested 'search' subview inside the File Explorer tab
* Introduces 'rightSidebarExplorerView' ('files' | 'search') state to manage the active subview inside the Explorer
* Adds a search button to the File Explorer toolbar and a back button to the search subview for seamless transition
* Exposes 'showRightSidebarFiles' and 'showRightSidebarSearch' store actions to route and seed search queries/include patterns
* Adapts file explorer keybindings, git status polling, and external workspace watchers to respect the active subview
* Maps legacy persisted search tab state to the new explorer search view for backward compatibility
This commit is contained in:
Jinjing
2026-06-11 02:13:16 -07:00
committed by GitHub
parent 5621f7686b
commit ba0d2fec16
39 changed files with 765 additions and 196 deletions
+32
View File
@@ -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,
+36 -4
View File
@@ -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)
@@ -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']
@@ -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(),
+15 -16
View File
@@ -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 {
<RecoverableRenderErrorBoundary
boundaryId="right-sidebar"
surface="right-sidebar"
resetKey={rightSidebarTab}
resetKey={
rightSidebarTab === 'explorer'
? `${rightSidebarTab}:${rightSidebarExplorerView}`
: rightSidebarTab
}
title={translate('auto.App.ed6b168d00', 'The right sidebar hit an error.')}
description={translate(
'auto.App.8d1e160ed1',
@@ -398,9 +398,7 @@ export default function MonacoEditor({
return
}
const state = useAppStore.getState()
state.seedFileSearchQuery(worktreeId, query)
state.setRightSidebarTab('search')
state.setRightSidebarOpen(true)
state.showRightSidebarSearch({ query })
}
})
@@ -1,6 +1,6 @@
/* eslint-disable max-lines -- File Explorer toolbar and row tests share element-walking fixtures. */
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { Ellipsis, ListCollapse, Loader2, RefreshCw } from 'lucide-react'
import { Ellipsis, ListCollapse, Loader2, RefreshCw, Search } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { DropdownMenuCheckboxItem } from '@/components/ui/dropdown-menu'
import { WorktreeOpenInMenuItems } from '@/components/sidebar/WorktreeOpenInMenu'
@@ -61,6 +61,19 @@ function findRefreshButton(node: unknown): ReactElementLike {
return found
}
function findSearchButton(node: unknown): ReactElementLike {
let found: ReactElementLike | null = null
visit(node, (entry) => {
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<Parameters<typeof FileExplorerToolbar>[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'
@@ -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 (
<div className="flex h-full min-h-0 flex-col">
<div className="flex h-8 min-h-8 items-center gap-2 border-b border-border px-2">
<Tooltip>
<TooltipTrigger asChild>
<Button
type="button"
variant="ghost"
size="icon-xs"
className="shrink-0 text-muted-foreground hover:text-foreground"
aria-label={translate(
'auto.components.right.sidebar.FileExplorer.4da4d89845',
'Back to Explorer'
)}
onClick={showRightSidebarFiles}
>
<ArrowLeft className="size-3" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom" sideOffset={4}>
{translate('auto.components.right.sidebar.FileExplorer.4da4d89845', 'Back to Explorer')}
</TooltipContent>
</Tooltip>
<span className="min-w-0 flex-1 truncate text-xs font-medium text-foreground">
{translate('auto.components.right.sidebar.FileExplorer.6ed5ce817b', 'Search')}
</span>
</div>
<div className="min-h-0 flex-1">
<SearchPanel />
</div>
</div>
)
}
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}
/>
<ScrollArea
className={cn(
@@ -575,4 +615,11 @@ function FileExplorerInner(): React.JSX.Element {
)
}
export default React.memo(FileExplorerInner)
const FileExplorerFilesMemo = React.memo(FileExplorerFiles)
function FileExplorer(): React.JSX.Element {
const explorerView = useAppStore((s) => s.rightSidebarExplorerView)
return explorerView === 'search' ? <ExplorerSearchSubview /> : <FileExplorerFilesMemo />
}
export default React.memo(FileExplorer)
@@ -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 (
<div className="flex h-8 min-h-8 items-center gap-2 border-b border-border px-2">
@@ -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}
>
<Search className="size-3" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom" sideOffset={4}>
{translate('auto.components.right.sidebar.FileExplorerToolbar.693cbeadd0', 'Search')}
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
type="button"
variant="ghost"
size="icon-xs"
className={cn(
'text-muted-foreground hover:text-foreground',
!canCollapseAll && 'cursor-not-allowed opacity-50'
)}
aria-label={translate(
'auto.components.right.sidebar.FileExplorerToolbar.6026b16950',
'Collapse All'
)}
disabled={!canCollapseAll}
onClick={onCollapseAll}
aria-disabled={!canCollapseAll}
// Why: native disabled buttons suppress Radix tooltip triggers in Chromium.
onClick={(event) => {
if (!canCollapseAll) {
event.preventDefault()
return
}
onCollapseAll()
}}
>
<ListCollapse className="size-3" />
</Button>
@@ -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 (
<div className="flex items-center justify-center h-full text-muted-foreground text-xs">
{translate("auto.components.right.sidebar.Search.98c8435e36", "Select a workspace to search")}</div>
{translate(
'auto.components.right.sidebar.Search.98c8435e36',
'Select a workspace to search'
)}
</div>
)
}
@@ -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 && (
<div className="px-2 py-1 text-[10px] text-muted-foreground border-b border-border">
{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)')}
</div>
)}
@@ -435,12 +453,17 @@ export default function Search(): React.JSX.Element {
{!fileSearchResults && fileSearchQuery && !fileSearchLoading && (
<div className="flex items-center justify-center h-32 text-muted-foreground text-xs">
{translate("auto.components.right.sidebar.Search.d56d140747", "Press Enter to search")}</div>
{translate('auto.components.right.sidebar.Search.d56d140747', 'Press Enter to search')}
</div>
)}
{!fileSearchQuery && (
<div className="flex items-center justify-center h-32 text-muted-foreground text-xs">
{translate("auto.components.right.sidebar.Search.1abfb25a66", "Type to search in files")}</div>
{translate(
'auto.components.right.sidebar.Search.1abfb25a66',
'Type to search in files'
)}
</div>
)}
</div>
</div>
@@ -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 =
@@ -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'])
})
})
@@ -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<T extends { id: RightSidebarTab }>(
export function getTopActivityBarLayout<T extends { id: ActiveRightSidebarTab }>(
items: readonly T[],
availableWidth: number | null,
activeId: RightSidebarTab
activeId: ActiveRightSidebarTab
): { visibleItems: T[]; overflowItems: T[] } {
if (!availableWidth || !Number.isFinite(availableWidth)) {
return { visibleItems: [...items], overflowItems: [] }
@@ -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 {
<TopActivityOverflowMenu
items={topActivityLayout.overflowItems}
activeTab={effectiveTab}
onSelect={setRightSidebarTab}
onSelect={selectActivityTab}
checksStatus={checksStatus}
/>
)}
@@ -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 {
<TopActivityOverflowMenu
items={topActivityLayout.overflowItems}
activeTab={effectiveTab}
onSelect={setRightSidebarTab}
onSelect={selectActivityTab}
checksStatus={checksStatus}
/>
)}
@@ -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({
<div className="flex min-h-0 flex-1 flex-col overflow-hidden">
<Suspense fallback={null}>
{effectiveTab === 'explorer' && <FileExplorer />}
{effectiveTab === 'search' && <SearchPanel />}
{effectiveTab === 'source-control' && <SourceControl />}
{effectiveTab === 'checks' && <ChecksPanel />}
{/* Why: SSH port forwarding still depends on the raw ports.detect data,
@@ -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: () => <div data-source-control />
}))
vi.mock('./Search', () => ({
default: () => <div data-search-panel />
}))
vi.mock('./ChecksPanel', () => ({
default: () => <div data-checks-panel />
}))
@@ -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')
})
@@ -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])
}
@@ -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,
@@ -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) {
@@ -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')
@@ -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
+5 -2
View File
@@ -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",
+5 -2
View File
@@ -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",
+5 -2
View File
@@ -7511,7 +7511,9 @@
"e041998cad": "生成を停止する"
},
"FileExplorer": {
"79b1537dd3": "ファイルを参照するワークスペースを選択"
"79b1537dd3": "ファイルを参照するワークスペースを選択",
"4da4d89845": "エクスプローラーに戻る",
"6ed5ce817b": "検索"
},
"FileExplorerBackgroundMenu": {
"3b5e2dcb8d": "新規フォルダー",
@@ -7547,7 +7549,8 @@
"78f133232c": "ドットファイルを表示",
"31b4c3195d": "エクスプローラーのその他の操作",
"d95e30fe28": "エクスプローラーを更新する",
"6026b16950": "すべて折りたたむ"
"6026b16950": "すべて折りたたむ",
"693cbeadd0": "検索"
},
"FileExplorerTreeStatus": {
"ce03835e1f": "このワークスペースにはファイルがありません",
+5 -2
View File
@@ -7511,7 +7511,9 @@
"e041998cad": "생성 중지"
},
"FileExplorer": {
"79b1537dd3": "파일을 찾아보려면 워크스페이스를 선택하세요."
"79b1537dd3": "파일을 찾아보려면 워크스페이스를 선택하세요.",
"4da4d89845": "탐색기로 돌아가기",
"6ed5ce817b": "검색"
},
"FileExplorerBackgroundMenu": {
"3b5e2dcb8d": "새 폴더",
@@ -7547,7 +7549,8 @@
"78f133232c": "도트 파일 표시",
"31b4c3195d": "추가 탐색기 작업",
"d95e30fe28": "탐색기 새로 고침",
"6026b16950": "모두 축소"
"6026b16950": "모두 축소",
"693cbeadd0": "검색"
},
"FileExplorerTreeStatus": {
"ce03835e1f": "이 워크스페이스에는 파일이 없습니다.",
+5 -2
View File
@@ -7511,7 +7511,9 @@
"e041998cad": "停止生成"
},
"FileExplorer": {
"79b1537dd3": "选择一个工作区来浏览文件"
"79b1537dd3": "选择一个工作区来浏览文件",
"4da4d89845": "返回资源管理器",
"6ed5ce817b": "搜索"
},
"FileExplorerBackgroundMenu": {
"3b5e2dcb8d": "新建文件夹",
@@ -7547,7 +7549,8 @@
"78f133232c": "显示点文件",
"31b4c3195d": "更多资源管理器操作",
"d95e30fe28": "刷新资源管理器",
"6026b16950": "全部折叠"
"6026b16950": "全部折叠",
"693cbeadd0": "搜索"
},
"FileExplorerTreeStatus": {
"ce03835e1f": "此工作区中没有文件",
@@ -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',
@@ -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
@@ -37,6 +37,7 @@ export function getStartupErrorFallbackUI(uiHydrated: boolean): PersistedUIState
sidebarWidth: 280,
rightSidebarOpen: true,
rightSidebarTab: 'explorer',
rightSidebarExplorerView: 'files',
rightSidebarWidth: 350,
groupBy: 'repo',
sortBy: 'name',
@@ -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' }
}
+87 -6
View File
@@ -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',
+128 -41
View File
@@ -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<string>()
} satisfies Omit<
EditorSlice['fileSearchStateByWorktree'][string],
'seedRequestId' | 'focusRequestId'
>
function defaultFileSearchState(): EditorSlice['fileSearchStateByWorktree'][string] {
return { ...DEFAULT_FILE_SEARCH_STATE, collapsedFiles: new Set<string>() }
}
export type DiffSource =
| 'unstaged'
@@ -303,13 +327,21 @@ export type EditorSlice = {
// Right sidebar
rightSidebarOpen: boolean
rightSidebarWidth: number
rightSidebarTab: RightSidebarTab
rightSidebarTabByWorktree: Record<string, RightSidebarTab>
rightSidebarTab: ActiveRightSidebarTab
rightSidebarExplorerView: RightSidebarExplorerView
rightSidebarTabByWorktree: Record<string, ActiveRightSidebarTab>
rightSidebarExplorerViewByWorktree: Record<string, RightSidebarExplorerView>
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<string>
seedRequestId?: number
focusRequestId?: number
}
>
updateFileSearchState: (
@@ -1364,12 +1397,91 @@ export const createEditorSlice: StateCreator<AppState, [], [], EditorSlice> = (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<string>(),
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<AppState, [], [], EditorSlice> = (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<AppState, [], [], EditorSlice> = (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<AppState, [], [], EditorSlice> = (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<AppState, [], [], EditorSlice> = (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,
@@ -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)
+26
View File
@@ -67,6 +67,8 @@ function createUIStore(): StoreApi<AppState> {
worktreesByRepo: {},
rightSidebarOpen: false,
rightSidebarWidth: 280,
rightSidebarTab: 'explorer',
rightSidebarExplorerView: 'files',
...createSettingsSearchState(args[0]),
...createWorktreeNavHistorySlice(...(args as Parameters<typeof createWorktreeNavHistorySlice>)),
...createUISlice(...(args as Parameters<typeof createUISlice>))
@@ -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', () => {
+7 -17
View File
@@ -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<AppState, [], [], UISlice> = (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<AppState, [], [], UISlice> = (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
@@ -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<AppState>)
@@ -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<AppState>)
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',
+32 -1
View File
@@ -611,6 +611,25 @@ function buildWorktreePurgeState(s: AppState, worktreeIds: string[]): Partial<Ap
}
return changed ? out : obj
}
const pruneRightSidebarTabByWorktree = (): AppState['rightSidebarTabByWorktree'] => {
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 = <T>(obj: Record<string, T>): Record<string, T> => {
let changed = false
const out = { ...obj }
@@ -683,7 +702,8 @@ function buildWorktreePurgeState(s: AppState, worktreeIds: string[]): Partial<Ap
activeTabIdByWorktree: omitByWorktree(s.activeTabIdByWorktree),
tabBarOrderByWorktree: omitByWorktree(s.tabBarOrderByWorktree),
pendingReconnectTabByWorktree: omitByWorktree(s.pendingReconnectTabByWorktree),
rightSidebarTabByWorktree: omitByWorktree(s.rightSidebarTabByWorktree),
rightSidebarTabByWorktree: pruneRightSidebarTabByWorktree(),
rightSidebarExplorerViewByWorktree: omitByWorktree(s.rightSidebarExplorerViewByWorktree ?? {}),
// Split-tab / unified tab state
unifiedTabsByWorktree: omitByWorktree(s.unifiedTabsByWorktree),
groupsByWorktree: omitByWorktree(s.groupsByWorktree),
@@ -1449,6 +1469,10 @@ export const createWorktreeSlice: StateCreator<AppState, [], [], WorktreeSlice>
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<AppState, [], [], WorktreeSlice>
activeFileIdByWorktree: nextActiveFileIdByWorktree,
activeBrowserTabIdByWorktree: nextActiveBrowserTabIdByWorktree,
activeTabTypeByWorktree: nextActiveTabTypeByWorktree,
rightSidebarExplorerViewByWorktree: nextRightSidebarExplorerViewByWorktree,
activeTabIdByWorktree: nextActiveTabIdByWorktree,
tabBarOrderByWorktree: nextTabBarOrderByWorktree,
pendingReconnectTabByWorktree: nextPendingReconnectTabByWorktree,
@@ -2185,6 +2210,10 @@ export const createWorktreeSlice: StateCreator<AppState, [], [], WorktreeSlice>
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<AppState, [], [], WorktreeSlice>
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<AppState, [], [], WorktreeSlice>
activeBrowserTabId,
activeTabType,
activeTabTypeByWorktree: nextActiveTabTypeByWorktree,
rightSidebarExplorerView: restoredRightSidebarExplorerView,
activeTabId,
everActivatedWorktreeIds: nextEverActivated,
...(nextWorktrees !== s.worktreesByRepo ? { worktreesByRepo: nextWorktrees } : {}),
+1
View File
@@ -407,6 +407,7 @@ export function getDefaultUIState(): PersistedUIState {
sidebarWidth: 280,
rightSidebarOpen: true,
rightSidebarTab: 'explorer',
rightSidebarExplorerView: 'files',
rightSidebarWidth: 350,
groupBy: 'repo',
sortBy: 'recent',
+3
View File
@@ -2616,6 +2616,8 @@ export type RightSidebarTab =
| 'source-control'
| 'checks'
| 'ports'
export type ActiveRightSidebarTab = Exclude<RightSidebarTab, 'search'>
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'