Added autocomplete suggestions to the bibles path setting field. Cleaned up a few things.

This commit is contained in:
Caleb Campbell
2025-07-17 08:06:23 +10:00
parent 62e3498cab
commit 218ddbfea7
5 changed files with 73 additions and 22 deletions

27
src/path-suggest.ts Normal file
View File

@@ -0,0 +1,27 @@
import { AbstractInputSuggest, App } from "obsidian";
export class PathSuggest extends AbstractInputSuggest<string> {
private textInputEl: HTMLInputElement | HTMLDivElement;
constructor(app: App, textInputEl: HTMLInputElement | HTMLDivElement) {
super(app, textInputEl);
this.textInputEl = textInputEl;
}
async getSuggestions(query: string): Promise<string[]> {
let searchPath = '';
if (await this.app.vault.adapter.exists(query)) searchPath = query;
let folders = (await this.app.vault.adapter.list(searchPath)).folders;
folders = folders.filter(folder => !folder.startsWith('.') && folder.startsWith(query));
return folders;
}
renderSuggestion(item: string, el: HTMLElement): void {
el.setText(item);
}
selectSuggestion(item: string, _: MouseEvent | KeyboardEvent): void {
this.setValue(item);
this.textInputEl.dispatchEvent(new Event('input'));
}
}