mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-11 14:45:30 +00:00
feat: better parsing for value strings
This commit is contained in:
@@ -10,11 +10,13 @@ import {
|
|||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
import { getTriggerText } from "./trigger";
|
import { getTriggerText } from "./trigger";
|
||||||
import uFuzzy from "@leeoniya/ufuzzy";
|
import uFuzzy from "@leeoniya/ufuzzy";
|
||||||
|
import { getAPI, DataviewApi } from "obsidian-dataview";
|
||||||
|
|
||||||
export class DataviewSuggester extends EditorSuggest<String> {
|
export class DataviewSuggester extends EditorSuggest<String> {
|
||||||
suggestionsList: string[] = [];
|
suggestionsList: string[] = [];
|
||||||
maxSuggestions: number;
|
maxSuggestions: number;
|
||||||
searcher: uFuzzy;
|
searcher: uFuzzy;
|
||||||
|
dataviewApi: DataviewApi;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
plugin: Plugin,
|
plugin: Plugin,
|
||||||
@@ -28,6 +30,7 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
|||||||
intraMode: singleErrorMode ? 1 : 0,
|
intraMode: singleErrorMode ? 1 : 0,
|
||||||
intraIns: allowExtraChars ? 1 : 0,
|
intraIns: allowExtraChars ? 1 : 0,
|
||||||
});
|
});
|
||||||
|
this.dataviewApi = getAPI(plugin.app);
|
||||||
}
|
}
|
||||||
|
|
||||||
onTrigger(
|
onTrigger(
|
||||||
@@ -117,7 +120,29 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
|||||||
|
|
||||||
// Add composite value "key:: value" to suggestions list
|
// Add composite value "key:: value" to suggestions list
|
||||||
for (const value of arrayVal) {
|
for (const value of arrayVal) {
|
||||||
const compositeValue = key + ":: " + value;
|
if (value === null || value === undefined) continue; // skip empty fields
|
||||||
|
|
||||||
|
// Convert value to string representation
|
||||||
|
let stringValue: string;
|
||||||
|
if (
|
||||||
|
typeof value === "string" ||
|
||||||
|
typeof value === "number" ||
|
||||||
|
typeof value === "boolean"
|
||||||
|
) {
|
||||||
|
stringValue = value.toString();
|
||||||
|
} else if (
|
||||||
|
this.dataviewApi.value.typeOf(value) === "link" &&
|
||||||
|
value.type === "file" &&
|
||||||
|
value.display !== undefined
|
||||||
|
) {
|
||||||
|
// value.toString always adds a display value to wiki-style links.
|
||||||
|
// parse wiki-style links without display value manually here to prevent this from happening for [[filename]]
|
||||||
|
stringValue = `[[${value.path.split("/").pop().replace(".md", "")}]]`;
|
||||||
|
} else {
|
||||||
|
stringValue = this.dataviewApi.value.toString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const compositeValue = `${key}:: ${stringValue}`;
|
||||||
if (newSuggestions.indexOf(compositeValue) === -1) {
|
if (newSuggestions.indexOf(compositeValue) === -1) {
|
||||||
newSuggestions.push(compositeValue);
|
newSuggestions.push(compositeValue);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user