Apply visual run resets to line range. #55
Merged
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 reset logic in visual runs doesn't take the line offset into account. The for loop iterates over the line's char indices, but the line-local index
i
is then used to index into theoriginal_classes
for the whole paragraph.Consider the string
"aa טֶ"
, which consists of five chars with the following subranges:0..1: a
1..2: a
2..3: space
3..5: ט
5..7: \u{5b6}
What happens in detail: When resolving the line
3..7
, the code previously iterated over both chars, and for the last chari=2
resolved to the original class of the space, settingreset_from
toSome(2)
. Then, all bytes from2
toline_str.len()
(which was4
), were reset to paragraph level. As a result, the first half ofט
was reset to0
.The result of all this is that the reordered visual runs now slice the
ט
in half because its level changes halfway through. In addition to a fix for the problem, I added the above example as a test case.