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.
pull/925/head
Zef Hemel 2024-07-07 10:13:53 +02:00
parent 9ea4b1c463
commit 4fa58aaafd
1 changed files with 0 additions and 19 deletions

View File

@ -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) { export async function tagComplete(completeEvent: CompleteEvent) {
const inLinkMatch = /(?:\[\[|\[.*\]\()([^\]]*)$/.exec( const inLinkMatch = /(?:\[\[|\[.*\]\()([^\]]*)$/.exec(
completeEvent.linePrefix, completeEvent.linePrefix,
@ -66,29 +63,13 @@ export async function tagComplete(completeEvent: CompleteEvent) {
return null; return null;
} }
const tagPrefix = match[0].substring(1); 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 // Query all tags with a matching parent
const allTags: any[] = await queryObjects<TagObject>("tag", { const allTags: any[] = await queryObjects<TagObject>("tag", {
filter: ["=", ["attr", "parent"], ["string", parent]],
select: [{ name: "name" }], select: [{ name: "name" }],
distinct: true, distinct: true,
}, 5); }, 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 { return {
from: completeEvent.pos - tagPrefix.length, from: completeEvent.pos - tagPrefix.length,
options: allTags.map((tag) => ({ options: allTags.map((tag) => ({