about summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-02-28 08:31:04 -0800
committerGitHub <noreply@github.com>2024-02-28 08:31:04 -0800
commit5cb45f9c16d1152bb84a02ccfac87a930cbbadda (patch)
tree2136c355c71294b73b5af09de3b185827358ab3f /modules
parentd679ae7dbb5d76bf5441239e1c9314cb229c1a0f (diff)
downloadvoidsky-5cb45f9c16d1152bb84a02ccfac87a930cbbadda.tar.zst
fix collissions in uitextview (#3017)
Diffstat (limited to 'modules')
-rw-r--r--modules/react-native-ui-text-view/ios/RNUITextView.swift19
1 files changed, 16 insertions, 3 deletions
diff --git a/modules/react-native-ui-text-view/ios/RNUITextView.swift b/modules/react-native-ui-text-view/ios/RNUITextView.swift
index 9c21d45b5..d51ee4e5d 100644
--- a/modules/react-native-ui-text-view/ios/RNUITextView.swift
+++ b/modules/react-native-ui-text-view/ios/RNUITextView.swift
@@ -108,14 +108,27 @@ class RNUITextView: UIView {
       fractionOfDistanceBetweenInsertionPoints: nil
     )
 
+    var lastUpperOffset: Int = 0
     for child in self.reactSubviews() {
       if let child = child as? RNUITextViewChild, let childText = child.text {
         let fullText = self.textView.attributedText.string
-        let range = fullText.range(of: childText)
-
+        
+        // We want to skip over the children we have already checked, otherwise we could run into
+        // collisions of similar strings (i.e. links that get shortened to the same hostname but
+        // different paths)
+        let startIndex = fullText.index(fullText.startIndex, offsetBy: lastUpperOffset)
+        let range = fullText.range(of: childText, options: [], range: startIndex..<fullText.endIndex)
+        
         if let lowerBound = range?.lowerBound, let upperBound = range?.upperBound {
-          if charIndex >= lowerBound.utf16Offset(in: fullText) && charIndex <= upperBound.utf16Offset(in: fullText) {
+          let lowerOffset = lowerBound.utf16Offset(in: fullText)
+          let upperOffset = upperBound.utf16Offset(in: fullText)
+          
+          if charIndex >= lowerOffset,
+             charIndex <= upperOffset
+          {
             return child
+          } else {
+            lastUpperOffset = upperOffset
           }
         }
       }