fix: inserted value should not use display value if display value is undefined

This commit is contained in:
daniel
2024-12-23 00:46:19 +01:00
parent 2d9194265a
commit b79d363c9f

View File

@@ -122,14 +122,16 @@ export class DataviewSuggester extends EditorSuggest<String> {
// If the value is a string, number or boolean, we can simply convert it to a string // If the value is a string, number or boolean, we can simply convert it to a string
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") { if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
stringValue = value.toString(); stringValue = value.toString();
} else if (dataviewAPI.value.typeOf(value) === "link" && value.type === "file" && value.display !== undefined) { } else if (dataviewAPI.value.typeOf(value) === "link" && value.type === "file") {
// value.toString always adds a display value to wiki-style links. // parse wiki-style links
// parse wiki-style links without display value manually here to prevent this from happening for [[filename]] if (value.display !== undefined) {
stringValue = `[[${value.path.split("/").pop().replace(".md", "")}|${value.display}]]`;
} else {
stringValue = `[[${value.path.split("/").pop().replace(".md", "")}]]`; stringValue = `[[${value.path.split("/").pop().replace(".md", "")}]]`;
}
} else { } else {
stringValue = dataviewAPI.value.toString(value); stringValue = dataviewAPI.value.toString(value);
} }
return `${key}:: ${stringValue}`; return `${key}:: ${stringValue}`;
} }