-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.ts
33 lines (26 loc) · 880 Bytes
/
main.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
import { Editor, Plugin } from 'obsidian';
import { ImageSearchPluginSettings, ImageSearchSettingTab, DEFAULT_SETTINGS } from 'image-search-settings-tab';
import { QueryModal } from 'query-modal';
export default class ImageSearchPlugin extends Plugin {
settings: ImageSearchPluginSettings;
async onload() {
await this.loadSettings();
this.addCommand({
id: 'insert-image',
name: 'Insert image',
editorCallback: (editor: Editor) => {
new QueryModal(this.app, this.settings, this.onSubmit(editor)).open();
}
});
this.addSettingTab(new ImageSearchSettingTab(this.app, this));
}
onSubmit = (editor: Editor) => (image: string) => {
editor.replaceSelection(`![](${image})`);
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}