diff options
author | Minseo Lee <itoupluk427@gmail.com> | 2024-02-29 09:51:56 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 09:51:56 +0900 |
commit | a1127bfcfc7ad080a5bd6210c6561788f1643db8 (patch) | |
tree | f2280d0308e4fc979f59f4f7abe3ef31a86390a2 /modules/react-native-ui-text-view/ios/RNUITextView.swift | |
parent | b723c4ca7ce22f673ea60e119da8552c452741da (diff) | |
parent | 7fd13cacfea4e9e4609ac2cfa11749544fc2f8f8 (diff) | |
download | voidsky-a1127bfcfc7ad080a5bd6210c6561788f1643db8.tar.zst |
Merge branch 'main' into patch-3
Diffstat (limited to 'modules/react-native-ui-text-view/ios/RNUITextView.swift')
-rw-r--r-- | modules/react-native-ui-text-view/ios/RNUITextView.swift | 18 |
1 files changed, 15 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..3fb55873d 100644 --- a/modules/react-native-ui-text-view/ios/RNUITextView.swift +++ b/modules/react-native-ui-text-view/ios/RNUITextView.swift @@ -108,14 +108,26 @@ class RNUITextView: UIView { fractionOfDistanceBetweenInsertionPoints: nil ) + var lastUpperBound: String.Index? = nil 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 range = fullText.range(of: childText, options: [], range: (lastUpperBound ?? String.Index(utf16Offset: 0, in: fullText) )..<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 { + lastUpperBound = upperBound } } } |