Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always use utf8 offsets #3024

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions modules/react-native-ui-text-view/ios/RNUITextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ 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

// 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)
Expand All @@ -128,7 +127,7 @@ class RNUITextView: UIView {
{
return child
} else {
lastUpperOffset = upperOffset
lastUpperBound = upperBound
}
}
}
Expand Down
Loading