From c6f5967003981909b7049ab76710103d0aacf058 Mon Sep 17 00:00:00 2001 From: cacosandon Date: Thu, 27 Jul 2023 10:06:27 -0400 Subject: [PATCH] feat: simplify previous char pattern and move default option to createMentionPlugin --- apps/www/content/docs/mention.mdx | 2 +- packages/mention/src/createMentionPlugin.ts | 1 + packages/mention/src/withMention.ts | 7 ++----- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/www/content/docs/mention.mdx b/apps/www/content/docs/mention.mdx index 2a84ef615d..03f609e166 100644 --- a/apps/www/content/docs/mention.mdx +++ b/apps/www/content/docs/mention.mdx @@ -65,7 +65,7 @@ A function to create the mention node. The pattern that matches the char before the trigger character - (default to `/^$|^\s$/` that matches beginning of line or space) + (default to `/^\s?$/` that matches beginning of line or space) diff --git a/packages/mention/src/createMentionPlugin.ts b/packages/mention/src/createMentionPlugin.ts index cf81a3274e..54a1bd8167 100644 --- a/packages/mention/src/createMentionPlugin.ts +++ b/packages/mention/src/createMentionPlugin.ts @@ -22,6 +22,7 @@ export const createMentionPlugin = createPluginFactory({ withOverrides: withMention, options: { trigger: '@', + triggerPreviousCharPattern: /^\s?$/, createMentionNode: (item) => ({ value: item.text }), }, plugins: [ diff --git a/packages/mention/src/withMention.ts b/packages/mention/src/withMention.ts index 7a17b92d11..ddadf493ce 100644 --- a/packages/mention/src/withMention.ts +++ b/packages/mention/src/withMention.ts @@ -114,11 +114,8 @@ export const withMention = < getPointBefore(editor, editor.selection) ) ); - - const spaceOrEmptyPattern = /^$|^\s$/; - const previousCharPattern = - triggerPreviousCharPattern ?? spaceOrEmptyPattern; - const matchesPreviousCharPattern = previousCharPattern.test(previousChar); + const matchesPreviousCharPattern = + triggerPreviousCharPattern?.test(previousChar); if (matchesPreviousCharPattern && text === trigger) { const data: TMentionInputElement = {