Skip to content

Ensure that subscripting AttributeSliceX behaves consistently regardless of index location #1382

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
merged 1 commit into from
Jul 1, 2025

Conversation

jmschonfeld
Copy link
Contributor

The AttributedString.Runs.AttributesSliceX types represent a run view that is sliced over a specific set of attributes. Iterating this view provides a coalesced range and the value of each attribute across this range. This view can also be subscripted at any AttributedString.Index to find the longest effective range of the specified attributes at a given index. The underlying implementation of this subscript had an early-return condition for when the run containing the index happened to be the final run in the slice, in which case the input index was used as the start of the returned range. This isn't correct - the start of this run is dependent upon where the specified attribute value begins and where the prior run boundary is (if applicable). In most situations you'll never hit this early-exit or it happens to be correct, but if you have an attribute slice over a substring and subscript into the middle of the final run, the returned range will be inputIndex ..< endOfRun rather than startOfRun ..< endOfRun. The added unit test failed due to the mismatch in ranges but by removing this early-return it now passes.

Resolves rdar://154342005

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld jmschonfeld requested a review from iCharlesHu July 1, 2025 00:20
@jmschonfeld jmschonfeld merged commit 4e679a9 into swiftlang:main Jul 1, 2025
16 checks passed
@jmschonfeld jmschonfeld deleted the attrstr/last-run-subscript branch July 1, 2025 18:23
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