From 9d13e05dbf0bb6430060ddf556006b1721444edc Mon Sep 17 00:00:00 2001
From: Paul Frazee <pfrazee@gmail.com>
Date: Fri, 18 Nov 2022 11:55:05 -0600
Subject: Fix rendering of mentions in composer

---
 src/view/com/composer/ComposePost.tsx | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

(limited to 'src/view/com/composer/ComposePost.tsx')

diff --git a/src/view/com/composer/ComposePost.tsx b/src/view/com/composer/ComposePost.tsx
index b89252418..b7abbed48 100644
--- a/src/view/com/composer/ComposePost.tsx
+++ b/src/view/com/composer/ComposePost.tsx
@@ -108,19 +108,24 @@ export const ComposePost = observer(function ComposePost({
       : undefined
 
   const textDecorated = useMemo(() => {
-    return (text || '').split(/(\s)/g).map((item, i) => {
-      if (
-        /^@[a-zA-Z0-9\.-]+$/g.test(item) &&
-        autocompleteView.knownHandles.has(item.slice(1))
-      ) {
-        return (
-          <Text key={i} style={{color: colors.blue3}}>
-            {item}
-          </Text>
-        )
-      }
-      return item
-    })
+    const re = /(@[a-z0-9\.]*)/gi
+    const segments = []
+    let match
+    let start = 0
+    let i = 0
+    while ((match = re.exec(text))) {
+      segments.push(text.slice(start, match.index))
+      segments.push(
+        <Text key={i++} style={{color: colors.blue3}}>
+          {match[0]}
+        </Text>,
+      )
+      start = match.index + match[0].length
+    }
+    if (start < text.length) {
+      segments.push(text.slice(start))
+    }
+    return segments
   }, [text])
 
   return (
@@ -194,7 +199,7 @@ export const ComposePost = observer(function ComposePost({
   )
 })
 
-const atPrefixRegex = /@([\S]*)$/i
+const atPrefixRegex = /@([a-z0-9\.]*)$/i
 function extractTextAutocompletePrefix(text: string) {
   const match = atPrefixRegex.exec(text)
   if (match) {
-- 
cgit 1.4.1

