feat: enhance Obsidian plugin with folder management features, including inclusion/exclusion settings and a status modal for real-time updates

This commit is contained in:
Anish Sarkar 2026-04-20 23:13:49 +05:30
parent 2251e464c7
commit 28d3c628f1
11 changed files with 267 additions and 154 deletions

View file

@ -0,0 +1,32 @@
import { type App, FuzzySuggestModal, type TFolder } from "obsidian";
/** Folder picker built on Obsidian's stock {@link FuzzySuggestModal}. */
export class FolderSuggestModal extends FuzzySuggestModal<TFolder> {
private readonly onPick: (path: string) => void;
private readonly excluded: Set<string>;
constructor(app: App, onPick: (path: string) => void, excluded: string[] = []) {
super(app);
this.onPick = onPick;
this.excluded = new Set(excluded.map((p) => p.replace(/^\/+|\/+$/g, "")));
this.setPlaceholder("Type to filter folders…");
}
getItems(): TFolder[] {
return this.app.vault
.getAllFolders(true)
.filter((f) => !this.excluded.has(this.toPath(f)));
}
getItemText(folder: TFolder): string {
return this.toPath(folder) || "/";
}
onChooseItem(folder: TFolder): void {
this.onPick(this.toPath(folder));
}
private toPath(folder: TFolder): string {
return folder.isRoot() ? "" : folder.path;
}
}