From 5449ea33261f2e563321f3b61fbb9fa408cd67e4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 25 Sep 2023 12:25:40 -0500 Subject: [PATCH] MentionPlugin: simplify regex and getMatch --- src/features/compose/editor/plugins/mention-plugin.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/features/compose/editor/plugins/mention-plugin.tsx b/src/features/compose/editor/plugins/mention-plugin.tsx index 09278d7f7..51c7b98b6 100644 --- a/src/features/compose/editor/plugins/mention-plugin.tsx +++ b/src/features/compose/editor/plugins/mention-plugin.tsx @@ -12,7 +12,7 @@ import { $createMentionNode, MentionNode } from '../nodes/mention-node'; import type { TextNode } from 'lexical'; -const MENTION_REGEX = new RegExp('(^|$|(?:^|\\s))([@])([a-z\\d_-]+(?:@[^@\\s]+)?)', 'i'); +const MENTION_REGEX = /(?:^|\s)@(?:[a-z\d_-]+(?:@[^@\s]+)?)/i; const MentionPlugin = (): JSX.Element | null => { const [editor] = useLexicalComposerContext(); @@ -31,8 +31,8 @@ const MentionPlugin = (): JSX.Element | null => { const match = MENTION_REGEX.exec(text); if (!match) return null; - const length = match[3].length + 1; - const start = match.index + match[1].length; + const length = match[0].length; + const start = match.index; const end = start + length; return { start, end };