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

winConsoleUIATextInfo: use rangeFromPoint instead of broken getVisibleRanges #10559

Merged
merged 12 commits into from
Dec 4, 2019

Conversation

michaelDCurran
Copy link
Member

@michaelDCurran michaelDCurran commented Nov 29, 2019

Link to issue number:

Fixes #10191
Fixes #10119

Summary of the issue:

In Windows consoles with UIA, NVDA currently makes use of IUIAutomationTextPattern::getVisibleRanges to find the bounds of what is visibly on screen. This is both for bounding the review cursor, and for collecting the on-screen text for diffing, in order to speak what has changed.
However, IUIAutomationTextPattern:getVisibleRanges can eventually start giving back junk text ranges that are positioned way above, and outside of the real visible bounds. This seems to start happening once a great deal of text has been scrolled up the screen.
This not only causes the review cursor to act strangely or get stuck when moving to the top or bottom, but it causes very old and invalid text to be spoken when things change on screen.

Description of how this pull request fixes the issue:

Instead of getVisibleRanges, use IUIAutomationTextPattern::rangeFromPoint at the top left and bottom right of the console window.

Testing performed:

Tested in both wsl (Ubuntu) and cmd.
Tested when older alpha builds of NVDA got into a state where the console no longer made sence with getVisibleRanges; this approach seemed to give back correct text and the review cursor no longer got stuck.

Known issues with pull request:

Like the older legacy winConsole support, if moving to the bottom with the review cursor and then going up by line, if there are blank lines in the console, these are not skipped. this is a little annoying for efficiency, but it is the same behaviour we originally had for many years, and blank lines are certainly better than invalid text or getting stuck.

Change log entry:

None.

…is very broken, use IUIAutomationTextPattern::rangeFromPoint for the top left and bottom right of the console window.
@michaelDCurran
Copy link
Member Author

@codeofdusk I'd appreciate your help in testing this where you can. I was originally against this approach, but since getvisibleRanges is very broken, I don't think we have a choice anymore.

@codeofdusk
Copy link
Contributor

@codeofdusk I'd appreciate your help in testing this where you can. I was originally against this approach, but since getvisibleRanges is very broken, I don't think we have a choice anymore.

After preliminary testing, I found that:

@michaelDCurran
Copy link
Member Author

michaelDCurran commented Nov 30, 2019 via email

@codeofdusk
Copy link
Contributor

I'm guessing that perhaps when review stops working when the console is flooded,  this is when in the existing code new text announced was invalid, and review also was broken? Or are you saying that this pr is actually worse? I think I can definitly address the  speed issue by putting back _getTextLines that calls IUIAutomationTextRange::getText directly. The base _getTextLines breaks text by unit line which is rather slow for UIA. Rather as this UIA implementation contains linefeed characters, we can just do a python string splitlines.

This PR is worse. Previously, autoread stopped completely but review still worked.

Also, a RuntimeError is thrown when the console exits after this PR.

@AppVeyorBot
Copy link

PR introduces Flake8 errors 😲

See test results for Failed build of commit 7518e2c85c

@codeofdusk
Copy link
Contributor

It seems that the move method still uses isTextRangeOffscreen. Is this intentional?

@codeofdusk
Copy link
Contributor

Also, it seems that your POSITION_LAST initialization assumes that _expandCollapseBeforeReview is True. Since #9802 was merged, there might not be a need to do this any more. Consider removing the _expandCollapseBeforeReview override.

@AppVeyorBot
Copy link

PR introduces Flake8 errors 😲

See test results for Failed build of commit 46b0888fd9

@michaelDCurran
Copy link
Member Author

@codeofdusk I think I have improved POSITION_FIRST / POSITION_LAST so that now review top and review bottom behave after a lot of text has scrolled up the screen.
I removed the usage of isTextRangeOffscreen, replacing it with calls to compareEndPoints
I have entirely removed _expandCollapseBeforeReview as requested.
I have also fixed the braille issues in #10191 by ensuring that a range is collapsed after a move.
If you could run through your tests again it would be much appreciated.
If there are still major issues after this, I'm afraide we may need to consider not having UIA support for consoles on by default in 2019.3 as there seem to be just too many console bugs we need to work around here.

@codeofdusk
Copy link
Contributor

@codeofdusk I think I have improved POSITION_FIRST / POSITION_LAST so that now review top and review bottom behave after a lot of text has scrolled up the screen.
I removed the usage of isTextRangeOffscreen, replacing it with calls to compareEndPoints
I have entirely removed _expandCollapseBeforeReview as requested.
I have also fixed the braille issues in #10191 by ensuring that a range is collapsed after a move.
If you could run through your tests again it would be much appreciated.
If there are still major issues after this, I'm afraide we may need to consider not having UIA support for consoles on by default in 2019.3 as there seem to be just too many console bugs we need to work around here.

Things are a lot better, but:

STR:

  1. Open a console.
  2. Invoke "review bottom line".
  3. Invoke "review current word".

Expected: the last word of the prompt is read out.
Actual: "blank" is reported.

@codeofdusk
Copy link
Contributor

@codeofdusk I think I have improved POSITION_FIRST / POSITION_LAST so that now review top and review bottom behave after a lot of text has scrolled up the screen.
I removed the usage of isTextRangeOffscreen, replacing it with calls to compareEndPoints
I have entirely removed _expandCollapseBeforeReview as requested.
I have also fixed the braille issues in #10191 by ensuring that a range is collapsed after a move.
If you could run through your tests again it would be much appreciated.
If there are still major issues after this, I'm afraide we may need to consider not having UIA support for consoles on by default in 2019.3 as there seem to be just too many console bugs we need to work around here.

Things are a lot better, but:

STR:

  1. Open a console.
  2. Invoke "review bottom line".
  3. Invoke "review current word".

Expected: the last word of the prompt is read out.
Actual: "blank" is reported.

Nevermind, I think that was confusion on my part (as now consoles have blank lines at the end per known issues). The confusing part is that word and line movement have different bounds (i.e. I can access some parts of the console with word review that I can't with line review, and vice versa).

…t directly with IUIAutomationTextRange::getText as WinConsoleUIATextInfo.text has been changed to return a space for empty ranges.
@michaelDCurran
Copy link
Member Author

michaelDCurran commented Dec 3, 2019 via email

Copy link
Contributor

@codeofdusk codeofdusk 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!

@codeofdusk
Copy link
Contributor

Also, I re-tested the console flooding case. This PR doesn't regress behavior.

@codeofdusk
Copy link
Contributor

@michaelDCurran When do you plan to merge this PR?

@michaelDCurran
Copy link
Member Author

michaelDCurran commented Dec 3, 2019 via email

Copy link
Collaborator

@LeonarddeR LeonarddeR left a comment

Choose a reason for hiding this comment

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

Just some small things

# Therefore use the bottom left, then move the to last character on that line.
tempInfo = self.__class__(obj, obj.location.bottomLeft)
tempInfo.expand(textInfos.UNIT_LINE)
UIATextInfo.move(tempInfo, textInfos.UNIT_CHARACTER, -1, endPoint="end")
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if we don't do this? We already expanded to line, so the endpoint should be the end of the line already?

visiLength = visiRanges.length
if visiLength > 0:
oldRange = self._rangeObj.clone()
boundingInfo = self.obj.makeTextInfo(textInfos.POSITION_ALL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consistency with other code

Suggested change
boundingInfo = self.obj.makeTextInfo(textInfos.POSITION_ALL)
boundingInfo = self.__class__(obj, textInfos.POSITION_ALL)

oldRange
and isTextRangeOffscreen(self._rangeObj, visiRanges)
and not isTextRangeOffscreen(oldRange, visiRanges)
oldInfo
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a small comment that explains what this if statement tries to do? It is hard to read at first glance.

@michaelDCurran
Copy link
Member Author

@LeonarddeR I have improved comments as requested. However, I did not take your suggestion of changing the makeTextInfo call into a direct WinConsoleUIATextInfo construction as this is not needed in the move method -- it can stay high-level. The only reason I did it in WinConsoleUIATextInfo's init method was because I was passing in _rangeObj which makeTextInfo does not allow.

source/NVDAObjects/UIA/winConsoleUIA.py Outdated Show resolved Hide resolved
Co-Authored-By: Leonard de Ruijter <leonardder@users.noreply.github.com>
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.

New UIA support and Braille not working Incorrect behavior of "review bottom line" in Windows Console
5 participants