Skip to content
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

Ensure TextInfo.getTextInChunks does not freeze, and provide new friendly compareable TextInfo endpoint properties #12253

Merged
merged 6 commits into from
Apr 6, 2021

Conversation

michaelDCurran
Copy link
Member

@michaelDCurran michaelDCurran commented Mar 31, 2021

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:

a.setEndPoint(b, "endToStart")

New code:

a.end = b.start

Is a's start at or past b's end?
Original code:

a.compareEndPoints(b, "startToEnd") >= 0

New code:

a.start >= b.end

TextInfo.getTextInChunks has been rewritten to use these new properties.

Testing strategy:

  • Performed exact steps in NVDA crashes when collecting text in Chunks from its edit controls #11613. No freeze occurs now, and all lines are correctly returned.
  • Performed the same steps but with a simple document in notepad. Previously this did not freeze, and it still does not. All lines are correctly returned.
  • Added unit tests for comparisons of start and end properties for less than, less than or equal to, equals, not equals, greater than or equal to, and greater than.
  • added unit tests for setting start and end.

Known issues with pull request:

None.

Change log entry:

Changes for developers:

  • TextInfo.getTextInChunks no longer freezes when called on Rich Edit controls such as the NVDA log viewer.
  • TextInfs now have start and end properties shich can be compared mathematically with operators such as < <= == != >= > and also can be set from each other. Thus it is now preferred to write code such as a.start <= b.end rather than a.compareEndPoints(b, "startToEnd") <= 0. And a.start = b.end rather than a.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.

  • Pull Request description is up to date.
  • Unit tests.
  • System (end to end) tests.
  • Manual tests.
  • User Documentation.
  • Change log entry.
  • Context sensitive help for GUI changes.

…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.
@AppVeyorBot
Copy link

See test results for failed build of commit 541d42907d

Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, way more readable.

@seanbudd seanbudd added this to the 2021.1 milestone Apr 6, 2021
Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@michaelDCurran michaelDCurran merged commit 0efeee4 into master Apr 6, 2021
@michaelDCurran michaelDCurran deleted the i11613 branch April 6, 2021 11:06
@cary-rowen
Copy link
Contributor

This change should belong to "Changes for developers" but it appears in "Bug Fixes".

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.

NVDA crashes when collecting text in Chunks from its edit controls
5 participants