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

Python 3: when in UIA based edit field, the deleted character is not spoken when pressing backspace #9928

Closed
zstanecic opened this issue Jul 15, 2019 · 10 comments
Labels
p3 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority
Milestone

Comments

@zstanecic
Copy link
Contributor

Steps to reproduce:

  1. go to any edit field, for example, skype chat, unigram chat, and or windows mail UIA app
  2. write something
  3. press backspace

Actual behavior:

the deleted caracter is not voiced

Expected behavior:

deleted character should be voiced

System configuration

NVDA installed/portable/running from source:

portable

NVDA version:

latest treshold py3 staging

Windows version:

windows 10 1903

Name and version of other software in use when reproducing the issue:

not applicable

Other information about your system:

n/a

Other questions

Does the issue still occur after restarting your PC?

yes

Have you tried any other versions of NVDA? If so, please report their behaviors.

no and not applicable, as it works in alpha snapshots

@LeonarddeR
Copy link
Collaborator

Can you please test this with a portable copy of normal threshold (not the py3 staging branch)?

@zstanecic
Copy link
Contributor Author

zstanecic commented Jul 15, 2019 via email

@LeonarddeR
Copy link
Collaborator

I was not able to reproduce this on latest threshold before Python 3 was merged in. Interesting ehough, I thought it was caused by me changing the postCaretMovedScriptHelper, but that doesn't seem to be the case.

@zstanecic
Copy link
Contributor Author

zstanecic commented Jul 15, 2019 via email

@zstanecic
Copy link
Contributor Author

zstanecic commented Jul 15, 2019 via email

@LeonarddeR
Copy link
Collaborator

LeonarddeR commented Jul 15, 2019

Ive been able to look into this some more, and it's pretty complicated.

The issue is in editableText.EditableText, line 101: if newBookmark and newBookmark!=bookmark:

First, let's try to explain something like a code example. For this, type hello into a word document and paste this into a python console:

x=nav.makeTextInfo("caret")
x==x
x!=x
y=x.copy()
x==y
x!=y
y.move("character", -1)
x==y
x!=y

Output under Python 2 is as follows:

>>> x=nav.makeTextInfo("caret")
>>> x==x
True
>>> x!=x
False
>>> y=x.copy()
>>> x==y
True
>>> x!=y
True
>>> y.move("character", -1)
-1
>>> x==y
False
>>> x!=y
True

Output under Python 3:

>>> x=nav.makeTextInfo("caret")
>>> x==x
True
>>> x!=x
False
>>> y=x.copy()
>>> x==y
True
>>> x!=y
False
>>> y.move("character", -1)
0
>>> x==y
True
>>> x!=y
False

The important case and only difference here is the first occurrence of x!=y, which is True on Python 2 and False on Python 3. I'm pretty sure that this insconsistency in the __eq__ and __neq__ operator clarify this issue.
Actually, a positive and negative comparison could never be True both as is the case on Python 2. So, this code has probably never worked as it really should have worked in the first place.

Cc @feerrenrut

@LeonarddeR LeonarddeR added the p3 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority label Jul 15, 2019
@LeonarddeR
Copy link
Collaborator

Another example:

  1. In word, type hello
  2. Position caret at the start of the line
  3. a=nav.makeTextInfo("caret")
  4. In the word document, press right arrow
  5. b=nav.makeTextInfo("caret")
  6. Now, a==b is False
  7. In the word document, press backspace
  8. Now, a==b is True.

This Compare method on UIA Text Ranges really behaves a bit strange. I'm afraid it is not very safe to rely on it for our equality comparison.

@zstanecic
Copy link
Contributor Author

zstanecic commented Jul 15, 2019 via email

@LeonarddeR
Copy link
Collaborator

LeonarddeR commented Jul 15, 2019 via email

feerrenrut pushed a commit that referenced this issue Jul 24, 2019
## Summary of the issue:

In text fields, when moving the caret with caret movement commands, such as the arrows, NVDA relies on bookmarks to find out whether the caret has moved.

In short:

1. You press left arrow
2. NVDA creates a bookmark of the current caret position
3. NVDA executes left arrow
4. For up to the caret movement timeout, NVDA tries to find out whether the caret has moved by creating new bookmarks and comparing them against the old.

However, for UIA, this comparison fails, as creating a bookmark at the end of a range and then removing one character from the end of the range results in a new bookmark that is equal to the former.

## Description of how this fixes the issue:

This PR introduces a different approach based on #9773. In first instance, this code caused #9786 to occur (i.e. editors in Chrome reporting the wrong caret position).

Compared to #9773, flow is now as follows:

-  In a loop in EditableText._hasCaretMoved, NVDA processes pedning events
-   If there is a focus event pending, the loop is exited
-   NVDA tries to find out whether the caret position has changed by creating a textInfo at the caret position
-   new code: only when this succeeds, NVDA checks for pending caret and textChange events. If the object that contains the caret has caretMovementDetectionUsesEvents set to False, it still ignores the caret events. This is what we do in IA2Web objects.

## Testing performed:

- Tested that deleted characters/words are again reported in UIA controls, such as MS Word
- Tested Notepad, Wordpad, Word Without UIA, Thunderbird, LibreOffice, start menu edit field, legacy command consoles and Skype Electron. Made sure that the caret was still correctly reported in all of them when moving with arrow keys or deleting.

## Known issues with pull request:

We can't set the caretMovementDetectionUsesEvents attribute to True on editableText.EditableText and then override it in other places, such as IA2Web. This is because EditableText precedes the IA2Web class as well as other classes in the mro Setting it on EditableText directly therefore makes it impossible for other classes to override the attribute. I solved this by making it a magic property on EditableText that first tries to call super before returning the default.

Fixes #9928
Follow up of  PR #9773
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Jul 24, 2019
@feerrenrut
Copy link
Contributor

Fixed in commit 75c8d00 via PR #9933

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority
Projects
None yet
Development

No branches or pull requests

4 participants