diff --git a/renderer/renderer.js b/renderer/renderer.js index 2f739db..8d9dd4e 100644 --- a/renderer/renderer.js +++ b/renderer/renderer.js @@ -545,15 +545,22 @@ const tab = getActiveTab(); const activePath = tab ? tab.filePath : null; - // If no folder is open, just re-render independent files + // No folder open: manage independent files section if (!currentRootPath) { + if (tabs.length === 0) { + // No tabs and no folder — hide sidebar + sidebar.classList.add('collapsed'); + sidebarTree.innerHTML = ''; + return; + } + sidebar.classList.remove('collapsed'); sidebarTree.innerHTML = ''; const indepSection = renderIndependentFiles(); if (indepSection) sidebarTree.appendChild(indepSection); return; } - // Re-render independent files section (files may have been added/removed) + // Folder is open: re-render independent files section (files may have been added/removed) const oldSection = sidebarTree.querySelector('.independent-files-section'); const newSection = renderIndependentFiles(); if (oldSection) oldSection.remove(); @@ -619,15 +626,6 @@ // Update modified state setModified(tab.isModified); - // Update sidebar highlight and independent files - updateSidebarHighlight(); - // If no folder is open but we have open files, ensure sidebar is visible - if (!currentRootPath && tabs.length > 0) { - sidebar.classList.remove('collapsed'); - } else if (!currentRootPath && tabs.length === 0) { - sidebar.classList.add('collapsed'); - } - // Notify main process about active file if (typeof window.electronAPI !== 'undefined') { window.electronAPI.tabSwitched(tab.filePath); @@ -782,6 +780,7 @@ tab.isModified = false; renderTabBar(); updateTitle(); + updateSidebarHighlight(); statusText.textContent = '已保存'; setTimeout(() => updateTitle(), 2000); } @@ -810,6 +809,7 @@ tab.isModified = false; renderTabBar(); updateTitle(); + updateSidebarHighlight(); statusText.textContent = '已保存'; setTimeout(() => updateTitle(), 2000); }