Debug folder navigation

This commit is contained in:
wz 2025-02-25 16:43:01 +01:00
parent fb6e624d35
commit cbcb566c13
3 changed files with 48 additions and 10 deletions

View file

@ -1,4 +1,4 @@
import { App, FuzzySuggestModal, TFolder } from "obsidian";
import { App, FuzzySuggestModal, TFolder, View } from "obsidian";
export class FolderSuggestModal extends FuzzySuggestModal<TFolder> {
folders: TFolder[];
@ -35,16 +35,45 @@ export class FolderSuggestModal extends FuzzySuggestModal<TFolder> {
}
onChooseItem(folder: TFolder): void {
// Reveal the folder in the navigation
const leaf = this.app.workspace.getLeaf();
this.app.workspace.revealLeaf(leaf);
// Focus the folder in the file explorer
// Get the file explorer leaf
const fileExplorer =
this.app.workspace.getLeavesOfType("file-explorer")[0];
if (fileExplorer) {
const fileExplorerView = fileExplorer.view as any;
fileExplorerView.revealFolder(folder);
if (!fileExplorer) return;
const view = fileExplorer.view as any;
// Ensure the file explorer is visible
this.app.workspace.revealLeaf(fileExplorer);
// Expand parent folders if needed
if (folder.parent && folder.parent.path) {
const pathParts = folder.parent.path.split("/");
let currentPath = "";
// Expand each parent folder
for (const part of pathParts) {
currentPath += (currentPath ? "/" : "") + part;
const parentFolder =
this.app.vault.getAbstractFileByPath(currentPath);
if (parentFolder && parentFolder instanceof TFolder) {
view.expandFolder(parentFolder, true);
}
}
}
// Expand the target folder itself
view.expandFolder(folder, true);
// Scroll the folder into view
const fileItem = view.fileItems[folder.path];
if (fileItem) {
fileItem.el.scrollIntoView({ behavior: "smooth", block: "center" });
// Highlight the folder temporarily
fileItem.el.addClass("nav-folder-title-highlighted");
setTimeout(
() => fileItem.el.removeClass("nav-folder-title-highlighted"),
2000,
);
}
}
}

View file

@ -27,7 +27,11 @@ export default class FolderNavigatorPlugin extends Plugin {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
this.settings = Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData(),
);
}
async saveSettings() {

5
styles.css Normal file
View file

@ -0,0 +1,5 @@
.nav-folder-title-highlighted {
background-color: var(--text-selection);
border-radius: 4px;
transition: background-color 0.3s ease;
}