Adds folder path autocompletion

Implements a folder suggestion component that provides
autocomplete for existing vault folders in folder path inputs.

This enhances the user experience by making it easier to select
existing folders when specifying file paths.
This commit is contained in:
AlexKucera committed 2025-09-03 10:16:11 +02:00
1 parent 346268cd68
commit 0e89488cf7
1 file changed
+34
+34
View File
@@ -0,0 +1,34 @@
/**
* Folder suggestion component for folder path inputs
* Provides autocomplete for existing vault folders
*/
import { App, AbstractInputSuggest } from 'obsidian';
export class FolderSuggest extends AbstractInputSuggest<string> {
private folders: string[];
private inputElement: HTMLInputElement;
constructor(app: App, inputEl: HTMLInputElement) {
super(app, inputEl);
this.inputElement = inputEl;
this.folders = ["/"].concat(this.app.vault.getAllFolders().map(folder => folder.path));
}
getSuggestions(inputStr: string): string[] {
const inputLower = inputStr.toLowerCase();
return this.folders.filter(folder =>
folder.toLowerCase().includes(inputLower)
);
}
renderSuggestion(folder: string, el: HTMLElement): void {
el.createEl("div", { text: folder });
}
selectSuggestion(folder: string): void {
this.inputElement.value = folder;
this.inputElement.dispatchEvent(new Event('input'));
this.close();
}
}