mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-07 19:08:43 +08:00
33 lines
895 B
TypeScript
33 lines
895 B
TypeScript
import { TAbstractFile, TFolder } from "obsidian";
|
|
import {TextInputSuggest} from "./TextInputSuggest";
|
|
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes
|
|
|
|
export class FolderSuggest extends TextInputSuggest<TFolder> {
|
|
getSuggestions(inputStr: string): TFolder[] {
|
|
const abstractFiles = this.app.vault.getAllLoadedFiles();
|
|
const folders: TFolder[] = [];
|
|
const lowerCaseInputStr = inputStr.toLowerCase();
|
|
|
|
abstractFiles.forEach((folder: TAbstractFile) => {
|
|
if (
|
|
folder instanceof TFolder &&
|
|
folder.path.toLowerCase().contains(lowerCaseInputStr)
|
|
) {
|
|
folders.push(folder);
|
|
}
|
|
});
|
|
|
|
return folders;
|
|
}
|
|
|
|
renderSuggestion(file: TFolder, el: HTMLElement): void {
|
|
el.setText(file.path);
|
|
}
|
|
|
|
selectSuggestion(file: TFolder): void {
|
|
this.inputEl.value = file.path;
|
|
this.inputEl.trigger("input");
|
|
this.close();
|
|
}
|
|
}
|