search by id
This commit is contained in:
parent
62a4f2ec56
commit
92f3e6bab8
13 changed files with 183 additions and 29 deletions
28
src/settings/suggesters/FileSuggest.ts
Normal file
28
src/settings/suggesters/FileSuggest.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import {TextInputSuggest} from './Suggest';
|
||||
import {TAbstractFile, TFile} from 'obsidian';
|
||||
|
||||
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.name.toLowerCase().contains(lowerCaseInputStr)) {
|
||||
files.push(file);
|
||||
}
|
||||
});
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
renderSuggestion(file: TFile, el: HTMLElement): void {
|
||||
el.setText(file.name);
|
||||
}
|
||||
|
||||
selectSuggestion(file: TFile): void {
|
||||
this.inputEl.value = file.name;
|
||||
this.inputEl.trigger('input');
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue