feat: auto-expand collapsed directories when focusing path in sidebar from dashboard navigation

- Add expandTarget option to focusPathInSidebar function to control directory expansion behavior
- Check if target directory is collapsed and click to expand before highlighting
- Pass expandTarget: true when navigating to directories from dashboard to ensure visibility
- Add async delay after expansion to allow DOM update before path highlighting
This commit is contained in:
Bruno Charest 2026-03-31 21:03:39 -04:00
parent 89c6889f42
commit 30b1d5fc93

View File

@ -2393,6 +2393,14 @@
} }
} }
if (lastTargetItem && options && options.expandTarget) {
const targetContainer = document.getElementById(`dir-${vaultName}-${targetPath}`);
if (targetContainer && targetContainer.classList.contains("collapsed")) {
lastTargetItem.click();
await new Promise((resolve) => setTimeout(resolve, 0));
}
}
// Clear previous path selections and highlight the final target // Clear previous path selections and highlight the final target
document.querySelectorAll(".tree-item.path-selected").forEach((el) => el.classList.remove("path-selected")); document.querySelectorAll(".tree-item.path-selected").forEach((el) => el.classList.remove("path-selected"));
if (lastTargetItem) { if (lastTargetItem) {
@ -2620,7 +2628,7 @@
if (clearBtn) clearBtn.style.display = "none"; if (clearBtn) clearBtn.style.display = "none";
await restoreSidebarTree(); await restoreSidebarTree();
if (entry.type === "directory") { if (entry.type === "directory") {
await focusPathInSidebar(entry.vault, entry.path, { alignToTop: true }); await focusPathInSidebar(entry.vault, entry.path, { alignToTop: true, expandTarget: true });
} else { } else {
await openFile(entry.vault, entry.path); await openFile(entry.vault, entry.path);
await focusPathInSidebar(entry.vault, entry.path, { alignToTop: false }); await focusPathInSidebar(entry.vault, entry.path, { alignToTop: false });