Fixed suggestion not saving after being clicked Changed from file name to path to ensure consistency in suggestion, otherwise you had to clear the whole textbox for suggestions to show up
23 lines
708 B
TypeScript
23 lines
708 B
TypeScript
import type { TAbstractFile } from 'obsidian';
|
|
import { AbstractInputSuggest, TFile } from 'obsidian';
|
|
|
|
export class FileSuggest extends AbstractInputSuggest<TFile> {
|
|
protected getSuggestions(query: string): TFile[] | Promise<TFile[]> {
|
|
const abstractFiles = this.app.vault.getAllLoadedFiles();
|
|
const files: TFile[] = [];
|
|
const lowerCaseInputStr = query.toLowerCase();
|
|
|
|
abstractFiles.forEach((file: TAbstractFile) => {
|
|
// Match against full path instead of just name
|
|
if (file instanceof TFile && file.path.toLowerCase().contains(lowerCaseInputStr)) {
|
|
files.push(file);
|
|
}
|
|
});
|
|
|
|
return files;
|
|
}
|
|
|
|
renderSuggestion(value: TFile, el: HTMLElement): void {
|
|
el.setText(value.path);
|
|
}
|
|
}
|