This commit is contained in:
Lost Paul 2023-03-19 22:33:55 +01:00
commit 3922550e0e
2 changed files with 54 additions and 1 deletions

View file

@ -0,0 +1,54 @@
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes and https://github.com/SilentVoid13/Templater
import { TAbstractFile, TFile } from "obsidian";
import { TextInputSuggest } from "./suggest";
import FolderNotesPlugin from "../main";
export enum FileSuggestMode {
TemplateFiles,
ScriptFiles,
}
export class FileSuggest extends TextInputSuggest<TFile> {
constructor(
public inputEl: HTMLInputElement,
private plugin: FolderNotesPlugin
) {
super(inputEl);
}
get_error_msg(mode: FileSuggestMode): string {
switch (mode) {
case FileSuggestMode.TemplateFiles:
return `Templates folder doesn't exist`;
case FileSuggestMode.ScriptFiles:
return `User Scripts folder doesn't exist`;
}
}
getSuggestions(input_str: string): TFile[] {
const files: TFile[] = [];
const lower_input_str = input_str.toLowerCase();
this.plugin.app.vault.getFiles().forEach((file: TAbstractFile) => {
if (
file instanceof TFile &&
file.path.toLowerCase().contains(lower_input_str)
) {
files.push(file);
}
});
return files;
}
renderSuggestion(file: TFile, el: HTMLElement): void {
el.setText(file.path);
}
selectSuggestion(file: TFile): void {
this.inputEl.value = file.path;
this.inputEl.trigger("input");
this.close();
}
}

View file

@ -12,7 +12,6 @@
display: none;
}
.nav-folder-collapse-indicator:hover {
cursor: pointer;
}