diff options
author | Hailey <me@haileyok.com> | 2024-02-28 13:28:27 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-28 13:28:27 -0800 |
commit | c7de733dff2d9b293d7f93de88f688e33db54b22 (patch) | |
tree | 00edc6a8a5d001cda90f83d15224e40869104d7a | |
parent | a697b39c48cca4565adacd99697822fa2db898a2 (diff) | |
download | voidsky-c7de733dff2d9b293d7f93de88f688e33db54b22.tar.zst |
always use utf8 offsets (#3024)
-rw-r--r-- | modules/react-native-ui-text-view/ios/RNUITextView.swift | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/modules/react-native-ui-text-view/ios/RNUITextView.swift b/modules/react-native-ui-text-view/ios/RNUITextView.swift index d51ee4e5d..3fb55873d 100644 --- a/modules/react-native-ui-text-view/ios/RNUITextView.swift +++ b/modules/react-native-ui-text-view/ios/RNUITextView.swift @@ -108,7 +108,7 @@ class RNUITextView: UIView { fractionOfDistanceBetweenInsertionPoints: nil ) - var lastUpperOffset: Int = 0 + 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 @@ -116,8 +116,7 @@ class RNUITextView: UIView { // 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) + 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 { let lowerOffset = lowerBound.utf16Offset(in: fullText) @@ -128,7 +127,7 @@ class RNUITextView: UIView { { return child } else { - lastUpperOffset = upperOffset + lastUpperBound = upperBound } } } |