From e488cf8f44a0d6b2b05e50a2cc2e5467ea6f7e37 Mon Sep 17 00:00:00 2001
From: Paul Frazee <pfrazee@gmail.com>
Date: Tue, 22 Nov 2022 14:30:35 -0600
Subject: Add support for links with no scheme in composer

---
 src/view/com/composer/ComposePost.tsx | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 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 c104041aa..cc9eca068 100644
--- a/src/view/com/composer/ComposePost.tsx
+++ b/src/view/com/composer/ComposePost.tsx
@@ -20,6 +20,7 @@ import {useStores} from '../../../state'
 import * as apilib from '../../../state/lib/api'
 import {ComposerOpts} from '../../../state/models/shell-ui'
 import {s, colors, gradients} from '../../lib/styles'
+import {detectLinkables} from '../../../lib/strings'
 
 const MAX_TEXT_LENGTH = 256
 const WARNING_TEXT_LENGTH = 200
@@ -108,24 +109,18 @@ export const ComposePost = observer(function ComposePost({
       : undefined
 
   const textDecorated = useMemo(() => {
-    const re = /(@[a-z0-9\.]*)|(https?:\/\/[\S]+)/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
+    return detectLinkables(text).map(v => {
+      if (typeof v === 'string') {
+        return v
+      } else {
+        return (
+          <Text key={i++} style={{color: colors.blue3}}>
+            {v.link}
+          </Text>
+        )
+      }
+    })
   }, [text])
 
   return (
-- 
cgit 1.4.1

