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() {