about summary refs log tree commit diff
path: root/src/lib/strings.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-12-20 16:32:04 -0600
committerPaul Frazee <pfrazee@gmail.com>2022-12-20 16:32:04 -0600
commit4f3bf401daf4e4883916d3b6e1b6f61792286d69 (patch)
treebebffd52f82e589b2c020ee3e38a7ab70db8be82 /src/lib/strings.ts
parentd83571a59e16aa3540b754683606b00f214258df (diff)
downloadvoidsky-4f3bf401daf4e4883916d3b6e1b6f61792286d69.tar.zst
Replace removed hasIndexes behavior
Diffstat (limited to 'src/lib/strings.ts')
-rw-r--r--src/lib/strings.ts28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/lib/strings.ts b/src/lib/strings.ts
index 2616141d6..bfa8848bd 100644
--- a/src/lib/strings.ts
+++ b/src/lib/strings.ts
@@ -82,13 +82,11 @@ export function extractEntities(
       } else if (!match[3].includes('.')) {
         continue // probably not a handle
       }
+      const start = text.indexOf(match[3], match.index) - 1
       ents.push({
         type: 'mention',
         value: match[3],
-        index: {
-          start: match.indices[2][0], // skip the (^|\s) but include the '@'
-          end: match.indices[3][1],
-        },
+        index: {start, end: start + match[3].length + 1},
       })
     }
   }
@@ -105,20 +103,16 @@ export function extractEntities(
         }
         value = `https://${value}`
       }
-      const index = {
-        start: match.indices[2][0], // skip the (^|\s)
-        end: match.indices[2][1],
+      const start = text.indexOf(match[2], match.index)
+      const index = {start, end: start + match[2].length}
+      // strip ending puncuation
+      if (/[.,;!?]$/.test(value)) {
+        value = value.slice(0, -1)
+        index.end--
       }
-      {
-        // strip ending puncuation
-        if (/[.,;!?]$/.test(value)) {
-          value = value.slice(0, -1)
-          index.end--
-        }
-        if (/[)]$/.test(value) && !value.includes('(')) {
-          value = value.slice(0, -1)
-          index.end--
-        }
+      if (/[)]$/.test(value) && !value.includes('(')) {
+        value = value.slice(0, -1)
+        index.end--
       }
       ents.push({
         type: 'link',