diff --git a/apps/x/apps/renderer/src/App.tsx b/apps/x/apps/renderer/src/App.tsx index f640b76a..30ac9032 100644 --- a/apps/x/apps/renderer/src/App.tsx +++ b/apps/x/apps/renderer/src/App.tsx @@ -617,6 +617,7 @@ function App() { const [graphStatus, setGraphStatus] = useState<'idle' | 'loading' | 'ready' | 'error'>('idle') const [graphError, setGraphError] = useState(null) const [isChatSidebarOpen, setIsChatSidebarOpen] = useState(true) + const [activeSection, setActiveSection] = useState('tasks') const isMac = typeof navigator !== 'undefined' && navigator.platform.toLowerCase().includes('mac') const collapsedLeftPaddingPx = (isMac ? MACOS_TRAFFIC_LIGHTS_RESERVED_PX : 0) + @@ -2019,13 +2020,24 @@ function App() { // Handle sidebar section changes - switch to chat view for tasks const handleSectionChange = useCallback((section: ActiveSection) => { + setActiveSection(section) if (section === 'tasks') { if (selectedBackgroundTask) return if (selectedPath || isGraphOpen) { void navigateToView({ type: 'chat', runId }) } + } else if (section === 'knowledge') { + // Restore the active file tab if one exists + const activeTab = fileTabs.find(t => t.id === activeFileTabId) + if (activeTab) { + void navigateToView({ type: 'file', path: activeTab.path }) + } else if (fileTabs.length > 0) { + const tab = fileTabs[0] + setActiveFileTabId(tab.id) + void navigateToView({ type: 'file', path: tab.path }) + } } - }, [isGraphOpen, navigateToView, runId, selectedBackgroundTask, selectedPath]) + }, [isGraphOpen, navigateToView, runId, selectedBackgroundTask, selectedPath, fileTabs, activeFileTabId]) // Knowledge quick actions const knowledgeFiles = React.useMemo(() => { @@ -2536,7 +2548,7 @@ function App() { canNavigateForward={canNavigateForward} collapsedLeftPaddingPx={collapsedLeftPaddingPx} > - {selectedPath && fileTabs.length > 1 ? ( + {activeSection === 'knowledge' && fileTabs.length > 1 ? ( - ) : !selectedPath && !isGraphOpen && !selectedBackgroundTask && chatTabs.length > 1 ? ( + ) : activeSection === 'tasks' && chatTabs.length > 1 ? (