From b42e1332626fc6138c878f703a7ceb45c333ea2e Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Wed, 23 Feb 2022 12:24:22 -0500 Subject: [PATCH 1/3] Adds support for multiline yaml array tags syntax (#4) --- main.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main.ts b/main.ts index 6b29516..2545386 100644 --- a/main.ts +++ b/main.ts @@ -28,7 +28,17 @@ class TagSuggest extends EditorSuggest { const tags: any = this.plugin.app.metadataCache.getTags(); return [...Object.keys(tags)].map((p) => p.split("#").pop()); } - + inRange(range: string) { + if (!range || !range.length) return false; + if (range.match(/^---\n/gm)?.length != 1) return false; + if (!/^tags?:/gm.test(range)) return false; + const split = range.split(/(^\w+:?\s*\n?)/gm); + for (let i = split.length - 1; i >= 0; i--) { + if (/(^\w+:?\s*\n?)/gm.test(split[i])) + return split[i].startsWith("tags:"); + } + return false; + } onTrigger( cursor: EditorPosition, editor: Editor, @@ -36,7 +46,9 @@ class TagSuggest extends EditorSuggest { ): EditorSuggestTriggerInfo | null { const lineContents = editor.getLine(cursor.line).toLowerCase(); const onFrontmatterTagLine = - lineContents.startsWith("tags:") || lineContents.startsWith("tag:"); + lineContents.startsWith("tags:") || + lineContents.startsWith("tag:") || + this.inRange(editor.getRange({ line: 0, ch: 0 }, cursor)); if (onFrontmatterTagLine) { const sub = editor.getLine(cursor.line).substring(0, cursor.ch); const match = sub.match(/(?<= )\S+$/)?.first(); From e28ca0bb23dad2f6eab9870fb239e0480dcc8fff Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Wed, 23 Feb 2022 12:28:36 -0500 Subject: [PATCH 2/3] Fixes issue with loading on iPhone and iPad (#5) --- main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.ts b/main.ts index 2545386..2163b55 100644 --- a/main.ts +++ b/main.ts @@ -51,7 +51,7 @@ class TagSuggest extends EditorSuggest { this.inRange(editor.getRange({ line: 0, ch: 0 }, cursor)); if (onFrontmatterTagLine) { const sub = editor.getLine(cursor.line).substring(0, cursor.ch); - const match = sub.match(/(?<= )\S+$/)?.first(); + const match = sub.match(/(\S+)$/)?.first(); if (match) { this.tags = this.getTags(); const matchData = { From 79a377dac78bf2d6f60420ddea1e2b6cdd45ea3f Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Wed, 23 Feb 2022 12:31:22 -0500 Subject: [PATCH 3/3] Autocompleting now also contextually inserts a comma or array entry (#3) --- main.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.ts b/main.ts index 2163b55..7a0427d 100644 --- a/main.ts +++ b/main.ts @@ -39,6 +39,7 @@ class TagSuggest extends EditorSuggest { } return false; } + inline = false; onTrigger( cursor: EditorPosition, editor: Editor, @@ -50,6 +51,9 @@ class TagSuggest extends EditorSuggest { lineContents.startsWith("tag:") || this.inRange(editor.getRange({ line: 0, ch: 0 }, cursor)); if (onFrontmatterTagLine) { + this.inline = + lineContents.startsWith("tags:") || + lineContents.startsWith("tag:"); const sub = editor.getLine(cursor.line).substring(0, cursor.ch); const match = sub.match(/(\S+)$/)?.first(); if (match) { @@ -82,6 +86,11 @@ class TagSuggest extends EditorSuggest { selectSuggestion(suggestion: string): void { if (this.context) { + if (this.inline) { + suggestion = `${suggestion},`; + } else { + suggestion = `${suggestion}\n -`; + } (this.context.editor as Editor).replaceRange( `${suggestion} `, this.context.start,