MentionPlugin: simplify regex and getMatch
This commit is contained in:
parent
7ff9d2ed3b
commit
5449ea3326
1 changed files with 3 additions and 3 deletions
|
@ -12,7 +12,7 @@ import { $createMentionNode, MentionNode } from '../nodes/mention-node';
|
||||||
|
|
||||||
import type { TextNode } from 'lexical';
|
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 MentionPlugin = (): JSX.Element | null => {
|
||||||
const [editor] = useLexicalComposerContext();
|
const [editor] = useLexicalComposerContext();
|
||||||
|
@ -31,8 +31,8 @@ const MentionPlugin = (): JSX.Element | null => {
|
||||||
const match = MENTION_REGEX.exec(text);
|
const match = MENTION_REGEX.exec(text);
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
|
|
||||||
const length = match[3].length + 1;
|
const length = match[0].length;
|
||||||
const start = match.index + match[1].length;
|
const start = match.index;
|
||||||
const end = start + length;
|
const end = start + length;
|
||||||
|
|
||||||
return { start, end };
|
return { start, end };
|
||||||
|
|
Loading…
Reference in a new issue