@@ -35,6 +35,7 @@ export const useAppLogic = (
3535 // --- Core Data & Selection State ---
3636 const [ selectedFilePath , setSelectedFilePath ] = React . useState < string | null > ( null ) ;
3737 const [ activeView , setActiveView ] = React . useState < 'structure' | 'code' > ( 'structure' ) ;
38+ const [ openFiles , setOpenFiles ] = React . useState < string [ ] > ( [ ] ) ;
3839
3940 // --- Layout State ---
4041 const windowSize = useWindowSize ( ) ;
@@ -73,6 +74,25 @@ export const useAppLogic = (
7374 selectedFilePath, setSelectedFilePath, setActiveView, showCharCount
7475 } ) ;
7576
77+ // --- Tab Management ---
78+ const handleTabSelect = React . useCallback ( ( path : string ) => {
79+ setOpenFiles ( prev => prev . includes ( path ) ? prev : [ ...prev , path ] ) ;
80+ handleFileTreeSelect ( path ) ;
81+ } , [ handleFileTreeSelect ] ) ;
82+
83+ const closeTab = React . useCallback ( ( path : string ) => {
84+ setOpenFiles ( prev => {
85+ const next = prev . filter ( p => p !== path ) ;
86+ if ( path === selectedFilePath ) {
87+ const closedIdx = prev . indexOf ( path ) ;
88+ const newSelected = next [ Math . min ( closedIdx , next . length - 1 ) ] ?? null ;
89+ setSelectedFilePath ( newSelected ) ;
90+ if ( ! newSelected ) setActiveView ( 'structure' ) ;
91+ }
92+ return next ;
93+ } ) ;
94+ } , [ selectedFilePath , setSelectedFilePath , setActiveView ] ) ;
95+
7696 // --- Search Hook ---
7797 const {
7898 isSearchOpen, setIsSearchOpen, searchResults, activeResultIndex,
@@ -129,6 +149,7 @@ export const useAppLogic = (
129149 setIsSettingsOpen ( false ) ;
130150 clearInteractionState ( ) ;
131151 setSelectedFilePath ( null ) ;
152+ setOpenFiles ( [ ] ) ;
132153 resetSearch ( ) ;
133154 setIsAiChatOpen ( false ) ;
134155 setIsFileRankOpen ( false ) ;
@@ -241,14 +262,15 @@ export const useAppLogic = (
241262 lastProcessedFiles, mobileView, stats,
242263 isSearchOpen, isFileRankOpen, isShortcutsOpen, searchResults, activeResultIndex, isMobile, isAiChatOpen,
243264 selectedFilePath, selectedFile, activeView,
265+ openFiles,
244266 searchQuery, searchOptions, activeMatchIndexInFile,
245267 recentProjects,
246268 } ,
247269 handlers : {
248270 setIsDragging, handleDrop : ( e : React . DragEvent ) => { setIsDragging ( false ) ; handleDrop ( e , isLoading ) ; } ,
249271 handleFileSelect, handleCopyAll, handleSave, handleReset, handleRefresh : ( ) => handleRefresh ( handleProcessing ) , handleCancel,
250272 setIsSettingsOpen, setToastMessage, setConfirmation,
251- handleDeleteFile, handleFileTreeSelect, setEditingPath, handleSaveEdit, handleToggleMarkdownPreview,
273+ handleDeleteFile, handleFileTreeSelect : handleTabSelect , closeTab , setEditingPath, handleSaveEdit, handleToggleMarkdownPreview,
252274 handleMouseDownResize,
253275 handleMobileViewToggle,
254276 setIsSearchOpen, setIsFileRankOpen, setIsShortcutsOpen, handleSearch, handleNavigate, setIsAiChatOpen,
0 commit comments