mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Merge branch 'main' of https://github.com/LostPaul/obsidian-folder-notes
This commit is contained in:
commit
3922550e0e
2 changed files with 54 additions and 1 deletions
54
src/suggesters/FileSuggester.ts
Normal file
54
src/suggesters/FileSuggester.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@
|
|||
display: none;
|
||||
}
|
||||
|
||||
|
||||
.nav-folder-collapse-indicator:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue