Skip to content

Commit b6f9f9d

Browse files
Only show tag completion when caret is at end of tag
1 parent 2ba4a91 commit b6f9f9d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/components/editor/plugins/tag-completion-plugin.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,21 @@ export default function TagCompletionPlugin() {
217217
return;
218218
}
219219

220-
const textUpToCursor = anchorNode
221-
.getTextContent()
222-
.slice(0, anchor.offset);
220+
const fullText = anchorNode.getTextContent();
221+
const textUpToCursor = fullText.slice(0, anchor.offset);
223222
const match = matchHashtag(textUpToCursor);
224223

224+
// Only show menu when caret is at the end of the tag
225+
const charAfterCursor = fullText[anchor.offset];
226+
if (
227+
charAfterCursor !== undefined &&
228+
/[^\s.,+*?$@|{}()^\-[\]\\/!%'"~=<>_:;#]/.test(charAfterCursor)
229+
) {
230+
closeMenu();
231+
if (debounceRef.current) clearTimeout(debounceRef.current);
232+
return;
233+
}
234+
225235
if (!match) {
226236
closeMenu();
227237
if (debounceRef.current) clearTimeout(debounceRef.current);

0 commit comments

Comments
 (0)