From d2ea82d2d568a0d94bf516736da976bf0ba09e21 Mon Sep 17 00:00:00 2001
From: Brian Kim <brian@tagg.id>
Date: Tue, 11 May 2021 12:10:39 -0700
Subject: Improved regex test

---
 src/components/comments/MentionInputControlled.tsx | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

(limited to 'src/components/comments/MentionInputControlled.tsx')

diff --git a/src/components/comments/MentionInputControlled.tsx b/src/components/comments/MentionInputControlled.tsx
index 642ef64c..892c9564 100644
--- a/src/components/comments/MentionInputControlled.tsx
+++ b/src/components/comments/MentionInputControlled.tsx
@@ -43,7 +43,13 @@ const MentionInputControlled: FC<MentionInputProps> = (
 
   const [keyboardText, setKeyboardText] = useState<string>('');
 
-  const validRegex = /.*\@[^ ]*$/;
+  const validRegex = () => {
+    if (partTypes.length === 0) {
+        return /.*\@[^ ]*$/;
+    } else {
+        return new RegExp(`.*\@${keywordByTrigger[partTypes[0].trigger]}.*$`);
+    }
+  };
 
   const {
     plainText,
@@ -134,7 +140,7 @@ const MentionInputControlled: FC<MentionInputProps> = (
   );
 
   const validateInput = (testString: string) => {
-      return validRegex.test(testString);
+      return validRegex().test(testString);
   }
 
   return (
-- 
cgit v1.2.3-70-g09d2

