From 6855381d5c6080302b443570a8dcccdd22455fc8 Mon Sep 17 00:00:00 2001
From: th
Date: Tue, 7 Apr 2026 22:02:17 +0200
Subject: [PATCH] tags2
---
public/js/modules/editor.js | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/public/js/modules/editor.js b/public/js/modules/editor.js
index 907060e..db3dace 100644
--- a/public/js/modules/editor.js
+++ b/public/js/modules/editor.js
@@ -465,11 +465,14 @@ body.addEventListener('input', () => {
function getTagQuery() {
const before = body.value.substring(0, body.selectionStart);
- // Find # preceded by whitespace or start of line, not part of heading (# + space)
- const m = before.match(/(?:^|[\s])#([a-zA-Z0-9_\/-]*)$/m);
- if (!m) return null;
- const start = before.length - m[0].length + (m[0].startsWith('#') ? 0 : 1); // skip leading whitespace
- return { start, query: m[1] };
+ const idx = before.lastIndexOf('#');
+ if (idx < 0) return null;
+ // Must be at start or after whitespace
+ if (idx > 0 && !/\s/.test(before[idx - 1])) return null;
+ // Everything after # to cursor must be valid tag chars (or empty)
+ const query = before.substring(idx + 1);
+ if (query && /[^a-zA-Z0-9_\/-]/.test(query)) return null;
+ return { start: idx, query };
}
function getAllTags() {
|