Ensure that subscripting AttributeSliceX behaves consistently regardless of index location #1382
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 anyAttributedString.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 beinputIndex ..< endOfRun
rather thanstartOfRun ..< endOfRun
. The added unit test failed due to the mismatch in ranges but by removing this early-return it now passes.Resolves rdar://154342005