Windows 10/11 Calculator: report correct number after paste by fetching the value directly from the UI element.#16672
Conversation
|
Hello Tristan, Thank you for your first contribution. As the original author of Calculator app module, I appreciate the effort taken to resolve this issue and update the code logic (and thank you for pointing out how tricky the logic is). A few general comments:
Enough musings - if I understand the proposed code changes correctly:
I don't expect new folks to be as detailed as above. I'll provide specific comments in the code fragments. Thanks. |
josephsl
left a comment
There was a problem hiding this comment.
Overall, this looks good. I advise reading NVDA development guide (or additional parts of the source code) so you can learn a few tricks here and there (one of them is ui.message which allows NVDA to both speak and braille whatever). If you have time, please do read Git commit logs for Windows App Essentials add-on so you can see how the Calculator ap module came to be.
| """App module for Windows 10 Calculator. | ||
| This is also the base app module for Windows 11 Calculator.""" | ||
|
|
||
| # This file has some fairly tricky logic, so here is a test plan to make sure |
There was a problem hiding this comment.
You don't have to write a test plan in the app module files - I think we should open a new discussion on adding test plans for Microsoft Store apps such as Calculator.
There was a problem hiding this comment.
Ok, I deleted the test plan for now. If the team does eventually decide you'd like to have such a thing, I'm happy to re-add it wherever you think it should go.
There was a problem hiding this comment.
Please add manual test plans to tests/manual. Manual test plans are welcome per the contributing guide https://github.com/nvaccess/nvda/blob/master/projectDocs/dev/githubPullRequestTemplateExplanationAndExamples.md#code-review-checklist
| # (for example "Display is 1" when it should be "Display is 12.34"). | ||
| # To fix this, we ignore the displayString sent via the UIA notification, | ||
| # and fetch the value directly from the UI element. | ||
| for child in resultElement.children: |
There was a problem hiding this comment.
Good catch - in full screen, expression text is marked as first child, whereas in compact (mini) mode, actual results text is the first child.
| # To fix this, we ignore the displayString sent via the UIA notification, | ||
| # and fetch the value directly from the UI element. | ||
| for child in resultElement.children: | ||
| if child.UIAAutomationId in ("CalculatorResults", "CalculatorAlwaysOnTopResults"): |
There was a problem hiding this comment.
What would happen if the display string reported by UIA notification is the same as what's shown on screen?
There was a problem hiding this comment.
I'm not sure I understand that situation you're considering, but I think the fix would still be applicable to that situation. For example, if you type "1+2=", the calculator will still show the correct answer and NVDA will report it correctly as well. The UIA notification in this scenario would set displayText="Display is 3", and that string is exactly the same as what we would pull from the element itself. So effectively, if the previous UIA notification was correct, then this does not change any behavior.
|
Hello Tristan, please use a descriptive title that explains what the PR does standalone. |
…ch and braille package.
|
@josephsl thanks so much for your insightful and kind comments. The code is quite good and I particularly appreciated how well commented it is. It must have taken a lot of work to get it to this point. This is my first time working with the NVDA project so I'm just not used to all the patterns involved. |
|
Hello Tristan, At least we got the basics of the fix right, and thank you for your willingness to think about our feedback/comments. I'm known for writing lots of comments in my own code - maybe I can't "keep my mouth shut" while programming... I think programming is a variation on writing essays (more so if you think about Python syntax and grammar). After all, working on apps like Calculator gave me writing materials in graduate school (I am attending a university in western United States). About the for loop logic: consider the following scenario:
The key is checking for value equality (== versus !=); a possible optimization is that NVDA doesn't have to fall back to default UIA notification event handling implementation (where it will report whatever the display string is as long as the element is focused on screen). This is what the call to "nextHandler" is - NVDA's event handling system could be viewed as an iterative "chain" where different modules can observe and handle events if they want to, otherwise default behavior (such as announcing things) will be performed. I think we can safely ignore this odd thing in this PR. If you want this to be part of NVDA 2024.3, I advise adding a changelog entry (we use Markdown syntax); if you want it in the next release after that, wait until 2024.3 enters beta phase (or shortly before) once NV Access people updates NVDA version in the source code. Then mark this PR as ready for review. Of course, since the issue may as well lie with Calculator executable itself, sending a "love letter" a.k.a. feedback to Microsoft from time to time about UIA notification event issue would be nice too. Thanks. |
seanbudd
left a comment
There was a problem hiding this comment.
Please add an entry to the changelog.
The general approach here looks good to me for the code changes.
| """App module for Windows 10 Calculator. | ||
| This is also the base app module for Windows 11 Calculator.""" | ||
|
|
||
| # This file has some fairly tricky logic, so here is a test plan to make sure |
There was a problem hiding this comment.
Please add manual test plans to tests/manual. Manual test plans are welcome per the contributing guide https://github.com/nvaccess/nvda/blob/master/projectDocs/dev/githubPullRequestTemplateExplanationAndExamples.md#code-review-checklist
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
Done. |
Using speech.cancelSpeech() eliminates the issue of duplicated speech announcements from UIA notifications. In fact, when pasting into the calculator, this is exactly what happens -- you get two notifications. So that's why I added the cancelSpeech() call. |
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... Files selected for processing (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Link to issue number:
Fixes #16573
Summary of the issue:
When pasting into the calculator, both speech and braille reported a truncated result (for example 1 instead of 12.34)
Description of user facing changes
When pasting into the Windows 10/11 calculator, the correct number is announced.
Description of development approach
Testing strategy:
Manual testing. Specifically, test to make sure that NVDA is announcing the whole number when pasted (example: 12.34 instead of just 1). Also, make sure that NVDA only announces said number once.
Known issues with pull request:
Nothing I can think of.
Code Review Checklist:
Summary by CodeRabbit