From 4fa58aaafd2d2f68cc71ca4079eb635beccd27d9 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Sun, 7 Jul 2024 10:13:53 +0200 Subject: [PATCH] Make tag auto-complete context independent Previously there was a (best effort) attempt to limit tag auto complete to only the type of object a had been applied to (e.g. an item, a page, a task). This is now removed, because I realized the need to reuse tags for various purposes and this filtering was annoying in practice. --- plugs/index/tags.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/plugs/index/tags.ts b/plugs/index/tags.ts index dd8cbf2a..46924e6d 100644 --- a/plugs/index/tags.ts +++ b/plugs/index/tags.ts @@ -50,9 +50,6 @@ export async function indexTags({ name, tree }: IndexTreeEvent) { ); } -const taskPrefixRegex = /^\s*[\-\*]\s+\[([^\]]+)\]/; -const itemPrefixRegex = /^\s*[\-\*]\s+/; - export async function tagComplete(completeEvent: CompleteEvent) { const inLinkMatch = /(?:\[\[|\[.*\]\()([^\]]*)$/.exec( completeEvent.linePrefix, @@ -66,29 +63,13 @@ export async function tagComplete(completeEvent: CompleteEvent) { return null; } const tagPrefix = match[0].substring(1); - let parent = "page"; - if (!completeEvent.parentNodes.find((n) => n.startsWith("FrontMatter:"))) { - if (taskPrefixRegex.test(completeEvent.linePrefix)) { - parent = "task"; - } else if (itemPrefixRegex.test(completeEvent.linePrefix)) { - parent = "item"; - } - } // Query all tags with a matching parent const allTags: any[] = await queryObjects("tag", { - filter: ["=", ["attr", "parent"], ["string", parent]], select: [{ name: "name" }], distinct: true, }, 5); - if (parent === "page") { - // Also add template, even though that would otherwise not appear because has "builtin" as a parent - allTags.push({ - name: "template", - }); - } - return { from: completeEvent.pos - tagPrefix.length, options: allTags.map((tag) => ({