Skip to content

NSRange to Range<AttributedString.Index> conversion should be relative to sliced boundaries #1050

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

Merged

Conversation

jmschonfeld
Copy link
Contributor

When converting an NSRange to a Range<AttributedString.Index> via our API, the conversion currently does not take the provided AttributedStringProtocol's startIndex/endIndex into account. This means that the NSRange's location is considered relative to the base's start for an AttributedSubstring rather than the substring's start, leading to conversion failing because the NSRange is often considered beyond the bounds of the slice.

This updates the conversion to operate on a slice of the underlying BigString so that the range calculation is performed from the slice's startIndex rather than the base's startIndex.

@jmschonfeld jmschonfeld requested a review from kperryua November 18, 2024 17:36
@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld jmschonfeld merged commit 1fff4b7 into swiftlang:main Nov 18, 2024
3 checks passed
@jmschonfeld jmschonfeld deleted the nsrange-range-conversion-offset branch November 18, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants