mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-11 14:45:30 +00:00
feat: only add suggester if dataview is enabled
This commit is contained in:
17
src/main.ts
17
src/main.ts
@@ -1,5 +1,6 @@
|
||||
import { App, Plugin, PluginSettingTab, Setting, TFile } from "obsidian";
|
||||
import { DataviewSuggester } from "./DataviewSuggester";
|
||||
import { getAPI } from "obsidian-dataview";
|
||||
|
||||
interface DataviewAutocompleteSettings {
|
||||
// mySetting: string;
|
||||
@@ -16,10 +17,6 @@ export default class DataviewAutocompletePlugin extends Plugin {
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
|
||||
// register suggester
|
||||
this.suggester = new DataviewSuggester(this, 10, true, true);
|
||||
this.registerEditorSuggest(this.suggester);
|
||||
|
||||
this.registerEvent(
|
||||
// @ts-ignore
|
||||
this.app.metadataCache.on("dataview:index-ready", () => {
|
||||
@@ -36,6 +33,18 @@ export default class DataviewAutocompletePlugin extends Plugin {
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
this.app.workspace.onLayoutReady(() => {
|
||||
// @ts-ignore
|
||||
if (!Object.keys(this.app.plugins.plugins).includes("dataview")) {
|
||||
console.warn("Dataview plugin not installed. Dataview Autocompletion plugin will not work.");
|
||||
} else {
|
||||
// register suggester, requires dataview to be loaded first.
|
||||
console.log("Registering dataview autocompletion suggester");
|
||||
this.suggester = new DataviewSuggester(this, 10, true, true);
|
||||
this.registerEditorSuggest(this.suggester);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onunload() {}
|
||||
|
||||
Reference in New Issue
Block a user