Ensure TextInfo.getTextInChunks does not freeze, and provide new friendly compareable TextInfo endpoint properties#12253
Merged
Merged
Conversation
…l comparisons with start and end properties of other TextInfo instances, For example: a.start <= b.end This way should now be preferred over calling compareEndPoints directly. and these start and end properties can also be set using other start and end properties For example: a.start = a.end This way should be preferred over calling setEndPoint directly.
See test results for failed build of commit 541d42907d |
feerrenrut
suggested changes
Apr 1, 2021
feerrenrut
left a comment
Contributor
There was a problem hiding this comment.
This looks great, way more readable.
Contributor
|
This change should belong to "Changes for developers" but it appears in "Bug Fixes". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Link to issue number:
Fixes #11613
Summary of the issue:
TextInfo.getTextInChunks could sometimes end up in an infinit loop when dealing with particular TextInfo implementations such as ITextDocument where setting start to the end of the document results in the start never quite getting there.
Description of how this pull request fixes the issue:
To work around this specific freeze, getTextInChunks now double checks that the start has really moved to the end of the last chunk. If not, we break out of the loop.
However, for a long time now we have wanted to make these TextInfo comparsons much more readable, which can aide in finding logic errors much easier.
To that end, TextInfo objects now have start and end properties, which can be compared mathematically, and also set from another, removing the need to use compareEndPoints or setEndPoint.
Some examples:
Setting a's end to b's start
Original code:
New code:
Is a's start at or past b's end?
Original code:
New code:
TextInfo.getTextInChunks has been rewritten to use these new properties.
Testing strategy:
Known issues with pull request:
None.
Change log entry:
Changes for developers:
< <= == != >= >and also can be set from each other. Thus it is now preferred to write code such asa.start <= b.endrather thana.compareEndPoints(b, "startToEnd") <= 0. Anda.start = b.endrather thana.setEndPoint(b, "startToend").Code Review Checklist:
This checklist is a reminder of things commonly forgotten in a new PR.
Authors, please do a self-review and confirm you have considered the following items.
Mark items you have considered by checking them.
You can do this when editing the Pull request description with an x:
[ ]becomes[x].You can also check the checkboxes after the PR is created.