mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-10 22:25:29 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1644899116 | ||
|
|
1debbb51f2 | ||
|
|
dd86b55bed | ||
|
|
8240045641 | ||
|
|
2dae1175f8 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "dataview-autocompletion",
|
"id": "dataview-autocompletion",
|
||||||
"name": "Dataview Autocompletion",
|
"name": "Dataview Autocompletion",
|
||||||
"version": "0.8.0",
|
"version": "0.8.2",
|
||||||
"minAppVersion": "0.15.0",
|
"minAppVersion": "0.15.0",
|
||||||
"description": "Adds autocompletion to Dataview metadata fields",
|
"description": "Adds autocompletion to Dataview metadata fields",
|
||||||
"author": "Daniel Bauer",
|
"author": "Daniel Bauer",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "obsidian-dataview-autocompletion",
|
"name": "obsidian-dataview-autocompletion",
|
||||||
"version": "0.8",
|
"version": "0.8.2",
|
||||||
"description": "This is a plugin for Obsidian that provides autocompletion for Dataview metadata fields",
|
"description": "This is a plugin for Obsidian that provides autocompletion for Dataview metadata fields",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ const createBaseConfig = (outdir) => ({
|
|||||||
src: "manifest.json",
|
src: "manifest.json",
|
||||||
dest: outdir,
|
dest: outdir,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
src: "styles.css",
|
|
||||||
dest: outdir,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -159,6 +159,8 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const page = dataviewApi.page(file.path);
|
const page = dataviewApi.page(file.path);
|
||||||
|
if (page === undefined) continue; // not a markdown file
|
||||||
|
|
||||||
const fields = Object.keys(page)
|
const fields = Object.keys(page)
|
||||||
.filter((k) => k !== "file")
|
.filter((k) => k !== "file")
|
||||||
.map((k) => [k, page[k]]);
|
.map((k) => [k, page[k]]);
|
||||||
@@ -218,6 +220,8 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
|||||||
const updateCompositeValues = [];
|
const updateCompositeValues = [];
|
||||||
|
|
||||||
const page = getAPI(this.app).page(file.path);
|
const page = getAPI(this.app).page(file.path);
|
||||||
|
if (page === undefined) return; // not a markdown file
|
||||||
|
|
||||||
const fields = Object.keys(page)
|
const fields = Object.keys(page)
|
||||||
.filter((k) => k !== "file")
|
.filter((k) => k !== "file")
|
||||||
.map((k) => [k, page[k]]);
|
.map((k) => [k, page[k]]);
|
||||||
@@ -297,13 +301,12 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
|||||||
for (const value of this.suggestionsRefs.get(file.path)!) {
|
for (const value of this.suggestionsRefs.get(file.path)!) {
|
||||||
this.suggestionsRefCount.set(value, this.suggestionsRefCount.get(value)! - 1);
|
this.suggestionsRefCount.set(value, this.suggestionsRefCount.get(value)! - 1);
|
||||||
if (this.suggestionsRefCount.get(value) === 0) {
|
if (this.suggestionsRefCount.get(value) === 0) {
|
||||||
console.debug("deleting value from suggestion index", value);
|
|
||||||
this.suggestionsList.splice(this.suggestionsList.indexOf(value), 1);
|
this.suggestionsList.splice(this.suggestionsList.indexOf(value), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.suggestionsRefs.delete(file.path);
|
this.suggestionsRefs.delete(file.path);
|
||||||
} else {
|
} else {
|
||||||
console.warn("Unknown update type:", type, file, oldPath);
|
console.debug("Unknown update type:", type, file, oldPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/main.ts
29
src/main.ts
@@ -1,6 +1,6 @@
|
|||||||
import { App, Plugin, PluginSettingTab, Setting, TFile } from "obsidian";
|
import { App, Plugin, PluginSettingTab, Setting, TFile } from "obsidian";
|
||||||
import { DataviewSuggester } from "./DataviewSuggester";
|
import { DataviewSuggester } from "./DataviewSuggester";
|
||||||
import { getAPI } from "obsidian-dataview";
|
import { getAPI, isPluginEnabled } from "obsidian-dataview";
|
||||||
import { SettingsTab } from "./SettingsTab";
|
import { SettingsTab } from "./SettingsTab";
|
||||||
|
|
||||||
interface DataviewAutocompleteSettings {
|
interface DataviewAutocompleteSettings {
|
||||||
@@ -15,18 +15,19 @@ const DEFAULT_SETTINGS: DataviewAutocompleteSettings = {
|
|||||||
|
|
||||||
export default class DataviewAutocompletePlugin extends Plugin {
|
export default class DataviewAutocompletePlugin extends Plugin {
|
||||||
settings: DataviewAutocompleteSettings;
|
settings: DataviewAutocompleteSettings;
|
||||||
suggester: DataviewSuggester | undefined;
|
suggester: DataviewSuggester;
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
this.addSettingTab(new SettingsTab(this.app, this));
|
this.addSettingTab(new SettingsTab(this.app, this));
|
||||||
|
|
||||||
|
this.suggester = new DataviewSuggester(this, 10, true, true);
|
||||||
|
this.registerEditorSuggest(this.suggester);
|
||||||
|
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.app.metadataCache.on("dataview:index-ready", () => {
|
this.app.metadataCache.on("dataview:index-ready", () => {
|
||||||
if (this.suggester !== undefined) {
|
this.suggester.onDataviewIndexReady();
|
||||||
this.suggester.onDataviewIndexReady();
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -35,24 +36,14 @@ export default class DataviewAutocompletePlugin extends Plugin {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
"dataview:metadata-change",
|
"dataview:metadata-change",
|
||||||
(type: string, file: TFile, oldPath?: string) => {
|
(type: string, file: TFile, oldPath?: string) => {
|
||||||
if (this.suggester !== undefined) {
|
this.suggester.onDataviewMetadataChange(type, file, oldPath);
|
||||||
this.suggester.onDataviewMetadataChange(type, file, oldPath);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.app.workspace.onLayoutReady(() => {
|
if (isPluginEnabled(this.app) && getAPI(this.app)?.index.initialized) {
|
||||||
// @ts-ignore
|
this.suggester.onDataviewIndexReady();
|
||||||
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() {}
|
onunload() {}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
This CSS file will be included with your plugin, and
|
|
||||||
available in the app when your plugin is enabled.
|
|
||||||
|
|
||||||
If your plugin does not need CSS, delete this file.
|
|
||||||
|
|
||||||
*/
|
|
||||||
3
test-vault/.obsidian/community-plugins.json
vendored
3
test-vault/.obsidian/community-plugins.json
vendored
@@ -1,5 +1,6 @@
|
|||||||
[
|
[
|
||||||
"sample-plugin",
|
"sample-plugin",
|
||||||
"dataview",
|
"dataview",
|
||||||
"obsidian-dataview-autocompletion"
|
"obsidian-dataview-autocompletion",
|
||||||
|
"dataview-autocompletion"
|
||||||
]
|
]
|
||||||
1
test-vault/not-a-markdown-file.json
Normal file
1
test-vault/not-a-markdown-file.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"test": "this is a test file"}
|
||||||
Reference in New Issue
Block a user