fix: 侧边栏高亮逻辑清理与边界情况修复
- 移除 loadTabState 中冗余的 updateSidebarHighlight 调用(switchToTab/closeTab 已覆盖) - 无文件夹+无标签时自动隐藏侧边栏(之前会空显示) - handleSave/handleSaveAs 后刷新侧边栏(文件路径变化时同步更新)
This commit is contained in:
+11
-11
@@ -545,15 +545,22 @@
|
|||||||
const tab = getActiveTab();
|
const tab = getActiveTab();
|
||||||
const activePath = tab ? tab.filePath : null;
|
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 (!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 = '';
|
sidebarTree.innerHTML = '';
|
||||||
const indepSection = renderIndependentFiles();
|
const indepSection = renderIndependentFiles();
|
||||||
if (indepSection) sidebarTree.appendChild(indepSection);
|
if (indepSection) sidebarTree.appendChild(indepSection);
|
||||||
return;
|
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 oldSection = sidebarTree.querySelector('.independent-files-section');
|
||||||
const newSection = renderIndependentFiles();
|
const newSection = renderIndependentFiles();
|
||||||
if (oldSection) oldSection.remove();
|
if (oldSection) oldSection.remove();
|
||||||
@@ -619,15 +626,6 @@
|
|||||||
// Update modified state
|
// Update modified state
|
||||||
setModified(tab.isModified);
|
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
|
// Notify main process about active file
|
||||||
if (typeof window.electronAPI !== 'undefined') {
|
if (typeof window.electronAPI !== 'undefined') {
|
||||||
window.electronAPI.tabSwitched(tab.filePath);
|
window.electronAPI.tabSwitched(tab.filePath);
|
||||||
@@ -782,6 +780,7 @@
|
|||||||
tab.isModified = false;
|
tab.isModified = false;
|
||||||
renderTabBar();
|
renderTabBar();
|
||||||
updateTitle();
|
updateTitle();
|
||||||
|
updateSidebarHighlight();
|
||||||
statusText.textContent = '已保存';
|
statusText.textContent = '已保存';
|
||||||
setTimeout(() => updateTitle(), 2000);
|
setTimeout(() => updateTitle(), 2000);
|
||||||
}
|
}
|
||||||
@@ -810,6 +809,7 @@
|
|||||||
tab.isModified = false;
|
tab.isModified = false;
|
||||||
renderTabBar();
|
renderTabBar();
|
||||||
updateTitle();
|
updateTitle();
|
||||||
|
updateSidebarHighlight();
|
||||||
statusText.textContent = '已保存';
|
statusText.textContent = '已保存';
|
||||||
setTimeout(() => updateTitle(), 2000);
|
setTimeout(() => updateTitle(), 2000);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user