generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
modal.ts
49 lines (40 loc) · 1.25 KB
/
modal.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {App, FuzzyMatch, FuzzySuggestModal, Modal} from 'obsidian';
import {SearchSetting} from './settings';
import SearchOnInternetPlugin from './main';
export class SearchModal extends FuzzySuggestModal<SearchSetting> {
plugin: SearchOnInternetPlugin;
query: string;
constructor(app: App, plugin: SearchOnInternetPlugin, query: string) {
super(app);
this.plugin = plugin;
this.setPlaceholder('');
this.query = query;
'${this.query}';
this.setInstructions([{command: '↑↓', purpose: 'to navigate'},
{command: '↵', purpose: `to search ${this.query}`},
{command: 'esc', purpose: 'to dismiss'}]);
}
onOpen() {
super.onOpen();
// const {contentEl} = this;
this.inputEl.focus();
}
onClose() {
super.onClose();
const {contentEl} = this;
contentEl.empty();
}
getItemText(item: SearchSetting): string {
return item.name;
}
renderSuggestion(item: FuzzyMatch<SearchSetting>, el: HTMLElement) {
super.renderSuggestion(item, el);
el.innerHTML = `Search on: ` + el.innerHTML;
}
getItems(): SearchSetting[] {
return this.plugin.settings.searches;
}
onChooseItem(item: SearchSetting, evt: MouseEvent | KeyboardEvent): void {
this.plugin.openSearch(item, this.query);
}
}