Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ function App() {
const handlePaletteOpenFile = useCallback(
(path: string) => {
const name = path.split(/[\\/]/).pop() ?? path
layoutStore.openFilePreview({ path, name, directory: currentDirectory })
layoutStore.openFileTab(
{ path, name, directory: currentDirectory, serverId: serverStore.getActiveServerId() },
'right',
)
},
[currentDirectory],
)
Expand Down
50 changes: 44 additions & 6 deletions src/components/BottomPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const SessionChangesPanel = lazy(() =>
)
const ContextPanel = lazy(() => import('./ContextPanel').then(module => ({ default: module.ContextPanel })))
const FileExplorer = lazy(() => import('./FileExplorer').then(module => ({ default: module.FileExplorer })))
const FileViewer = lazy(() => import('./FileViewer').then(module => ({ default: module.FileViewer })))
const McpPanel = lazy(() => import('./McpPanel').then(module => ({ default: module.McpPanel })))
const SkillPanel = lazy(() => import('./SkillPanel').then(module => ({ default: module.SkillPanel })))
const WorktreePanel = lazy(() => import('./WorktreePanel').then(module => ({ default: module.WorktreePanel })))
Expand Down Expand Up @@ -84,7 +85,6 @@ export const BottomPanel = memo(function BottomPanel({ directory, serverId, term
<FilesContent
activeTab={activeTab}
directory={directory ?? ''}
isPanelResizing={isPanelResizing}
sessionId={sessionId}
serverId={serverId}
/>
Expand Down Expand Up @@ -115,6 +115,13 @@ export const BottomPanel = memo(function BottomPanel({ directory, serverId, term
</Suspense>
) : null}

{/* 打开的文件保持挂载:切走再切回来,编辑态与滚动位置都还在 */}
<div className={activeTab.type === 'file' ? 'h-full' : 'hidden'}>
<Suspense fallback={<PanelFallback />}>
<FileContent activeTab={activeTab} serverId={serverId} sessionId={sessionId} isPanelResizing={isPanelResizing} />
</Suspense>
</div>

{activeTab.type === 'terminal' ? (
<Suspense fallback={<PanelFallback />}>
<TerminalContent activeTab={activeTab} />
Expand Down Expand Up @@ -206,15 +213,13 @@ const TerminalContent = memo(function TerminalContent({ activeTab }: TerminalCon
interface FilesContentProps {
activeTab: PanelTab
directory?: string
isPanelResizing?: boolean
sessionId?: string | null
serverId?: string
}

const FilesContent = memo(function FilesContent({
activeTab,
directory,
isPanelResizing = false,
sessionId,
serverId,
}: FilesContentProps) {
Expand All @@ -229,10 +234,7 @@ const FilesContent = memo(function FilesContent({
panelTabId={tab.id}
directory={directory}
serverId={serverId}
previewFile={tab.previewFile ?? null}
previewFiles={tab.previewFiles ?? []}
position="bottom"
isPanelResizing={isPanelResizing}
sessionId={sessionId}
/>
</div>
Expand All @@ -241,6 +243,42 @@ const FilesContent = memo(function FilesContent({
)
})

interface FileContentProps {
activeTab: PanelTab
serverId?: string
sessionId?: string | null
isPanelResizing?: boolean
}

/** 打开的文件:每个文件一个标签页,内容整页展示 */
const FileContent = memo(function FileContent({
activeTab,
serverId,
sessionId,
isPanelResizing = false,
}: FileContentProps) {
const { panelTabs } = useLayoutStore()
const fileTabs = panelTabs.filter(t => t.position === 'bottom' && t.type === 'file')

return (
<>
{fileTabs.map(tab => (
<div key={tab.id} className={tab.id === activeTab.id ? 'h-full' : 'hidden'}>
{tab.previewFile && (
<FileViewer
tabId={tab.id}
file={tab.previewFile}
serverId={serverId}
sessionId={sessionId}
isPanelResizing={isPanelResizing}
/>
)}
</div>
))}
</>
)
})

interface ChangesContentProps {
activeTab: PanelTab
directory?: string
Expand Down
43 changes: 22 additions & 21 deletions src/components/FileExplorer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { FileExplorer } from './FileExplorer'
import { layoutStore } from '../store/layoutStore'
import type { DesktopPlatform } from '../utils/tauri'

const {
Expand All @@ -21,16 +22,6 @@ vi.mock('../hooks', () => ({
useFileExplorer: (options?: unknown) => useFileExplorerMock(options),
}))

vi.mock('../hooks/useVerticalSplitResize', () => ({
useVerticalSplitResize: () => ({
splitHeight: 200,
isResizing: false,
resetSplitHeight: vi.fn(),
handleResizeStart: vi.fn(),
handleTouchResizeStart: vi.fn(),
}),
}))

vi.mock('../utils/tauri', () => ({
isTauri: () => isTauriMock(),
isTauriMobile: () => isTauriMobileMock(),
Expand Down Expand Up @@ -66,22 +57,36 @@ describe('FileExplorer', () => {
expandedPaths: new Set<string>(),
toggleExpand: vi.fn(),
refresh: vi.fn(),
previewContent: null,
previewLoading: false,
previewError: null,
loadPreview: vi.fn(),
clearPreview: vi.fn(),
effectiveDirectory: 'C:/repo',
fileStatus: new Map(),
})
})

it('opens a file in a new panel tab instead of pushing a preview from the bottom', () => {
const openFileTab = vi.spyOn(layoutStore, 'openFileTab')

render(
<FileExplorer
panelTabId="files-1"
directory="C:/repo"
serverId="server-1"
position="right"
/>,
)

fireEvent.click(screen.getByRole('button', { name: 'app.ts' }))

expect(openFileTab).toHaveBeenCalledWith(
{ path: 'src/app.ts', name: 'app.ts', directory: 'C:/repo', serverId: 'server-1' },
'right',
)
})

it('reveals the selected file in the system explorer from the context menu', async () => {
render(
<FileExplorer
panelTabId="files-1"
directory="C:/repo"
previewFile={null}
previewFiles={[]}
position="right"
/>,
)
Expand All @@ -101,8 +106,6 @@ describe('FileExplorer', () => {
<FileExplorer
panelTabId="files-1"
directory="C:/repo"
previewFile={null}
previewFiles={[]}
position="right"
/>,
)
Expand All @@ -118,8 +121,6 @@ describe('FileExplorer', () => {
<FileExplorer
panelTabId="files-1"
directory="C:/repo"
previewFile={null}
previewFiles={[]}
position="right"
/>,
)
Expand Down
Loading
Loading