generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapted suggesters from [templater](https://github.com/SilentVoid13/Templater) and [periodic notes](https://github.com/liamcain/obsidian-periodic-notes).
- Loading branch information
1 parent
06e4123
commit e457677
Showing
6 changed files
with
358 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes | ||
// here adapted from Templater plugin https://github.com/SilentVoid13/Templater | ||
|
||
import { TAbstractFile, TFile, TFolder } from "obsidian"; | ||
|
||
import { TextInputSuggest } from "./suggest"; | ||
|
||
export class FileSuggest extends TextInputSuggest<TFile> { | ||
getSuggestions(inputStr: string): TFile[] { | ||
const abstractFiles = this.app.vault.getAllLoadedFiles(); | ||
const files: TFile[] = []; | ||
const lowerCaseInputStr = inputStr.toLowerCase(); | ||
|
||
abstractFiles.forEach((file: TAbstractFile) => { | ||
if ( | ||
file instanceof TFile && | ||
file.extension === "md" && | ||
file.path.toLowerCase().contains(lowerCaseInputStr) | ||
) { | ||
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(); | ||
} | ||
} | ||
|
||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes | ||
// here adapted from Templater plugin https://github.com/SilentVoid13/Templater | ||
|
||
import { TAbstractFile, TFolder } from "obsidian"; | ||
import { TextInputSuggest } from "./suggest"; | ||
|
||
export class FolderSuggest extends TextInputSuggest<TFolder> { | ||
getSuggestions(inputStr: string): TFolder[] { | ||
const abstractFiles = 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(); | ||
} | ||
} |
Oops, something went wrong.