always use utf8 offsets (#3024)

zio/stable
Hailey 2024-02-28 13:28:27 -08:00 committed by GitHub
parent a697b39c48
commit c7de733dff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 4 deletions

View File

@ -108,7 +108,7 @@ class RNUITextView: UIView {
fractionOfDistanceBetweenInsertionPoints: nil fractionOfDistanceBetweenInsertionPoints: nil
) )
var lastUpperOffset: Int = 0 var lastUpperBound: String.Index? = nil
for child in self.reactSubviews() { for child in self.reactSubviews() {
if let child = child as? RNUITextViewChild, let childText = child.text { if let child = child as? RNUITextViewChild, let childText = child.text {
let fullText = self.textView.attributedText.string 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 // 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 // collisions of similar strings (i.e. links that get shortened to the same hostname but
// different paths) // different paths)
let startIndex = fullText.index(fullText.startIndex, offsetBy: lastUpperOffset) let range = fullText.range(of: childText, options: [], range: (lastUpperBound ?? String.Index(utf16Offset: 0, in: fullText) )..<fullText.endIndex)
let range = fullText.range(of: childText, options: [], range: startIndex..<fullText.endIndex)
if let lowerBound = range?.lowerBound, let upperBound = range?.upperBound { if let lowerBound = range?.lowerBound, let upperBound = range?.upperBound {
let lowerOffset = lowerBound.utf16Offset(in: fullText) let lowerOffset = lowerBound.utf16Offset(in: fullText)
@ -128,7 +127,7 @@ class RNUITextView: UIView {
{ {
return child return child
} else { } else {
lastUpperOffset = upperOffset lastUpperBound = upperBound
} }
} }
} }