Skip to content

Fix off by one text length in EditTextInfo#18767

Merged
SaschaCowley merged 5 commits into
nvaccess:masterfrom
LeonarddeR:removeEditTextOffByOne
Sep 2, 2025
Merged

Fix off by one text length in EditTextInfo#18767
SaschaCowley merged 5 commits into
nvaccess:masterfrom
LeonarddeR:removeEditTextOffByOne

Conversation

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Link to issue number:

Related to #18744
Follow up of #18348

Summary of the issue:

When working on #18744, I again stumbled upon the fact that the story length reported by EditTextInfo is too high. This was discovered after system test failures caused by #18348, i.e. reporting of an extraneous blank at the end of the document when using NVDA review cursor. Note, this is not a bug in #18348 and was accounted for in #18744 after the test failure.

To reproduce

  1. Open notepad classic
  2. type a
  3. Position the caret at the end of the line
  4. Press nvda+delete or nvda+numpad delete

Observe that NVDA reports 50%, not 100%
Observe that nav.makeTextInfo("caret")._getStoryLength() reports 2, not 1

Description of user facing changes:

None

Description of developer facing changes:

None

Description of development approach:

Fixed the off by one errors by removing the + 1 cases.

Testing strategy:

Tested str from this pr.

Known issues with pull request:

None

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@coderabbitai summary

@LeonarddeR LeonarddeR force-pushed the removeEditTextOffByOne branch from 79d950f to d0babfe Compare August 21, 2025 05:51
@LeonarddeR LeonarddeR marked this pull request as ready for review August 21, 2025 05:51
Copilot AI review requested due to automatic review settings August 21, 2025 05:51
@LeonarddeR LeonarddeR requested a review from a team as a code owner August 21, 2025 05:51
@LeonarddeR LeonarddeR marked this pull request as draft August 21, 2025 06:33
@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

I think that the failing test might actually be a good thing. Will look into this.

This comment was marked as outdated.

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

It was indeed a bug in the system test, or rather, the system test compensated for the off by one bug. Review cursor behavior in Notepad is now in line with notepad++, Word, Firefox, etc.

@LeonarddeR LeonarddeR marked this pull request as ready for review August 27, 2025 15:48
@LeonarddeR LeonarddeR requested a review from Copilot August 27, 2025 15:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an off-by-one error in the EditTextInfo class that was causing incorrect text length calculations, particularly affecting caret position reporting in classic Notepad and other Win32 edit controls.

  • Removes erroneous + 1 operations in _getStoryLength() method that were causing text length to be reported as one character longer than actual
  • Updates protected text masking to use correct length calculation
  • Adjusts system tests to expect correct character reporting instead of erroneous "blank" characters

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
user_docs/en/changes.md Adds changelog entry documenting the text position accuracy fix
source/NVDAObjects/window/edit.py Removes off-by-one errors in story length calculation and protected text handling
source/textInfos/offsets.py Removes unnecessary length constraint in uniscribe offset calculation
tests/system/robot/symbolPronunciationTests.py Updates test expectations to match corrected behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@SaschaCowley SaschaCowley added merge-early Merge Early in a developer cycle conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. labels Aug 28, 2025
Comment thread source/NVDAObjects/window/edit.py Outdated
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
@SaschaCowley SaschaCowley merged commit a514710 into nvaccess:master Sep 2, 2025
39 of 40 checks passed
@github-actions github-actions Bot added this to the 2026.1 milestone Sep 2, 2025
nvdaes added a commit to nvdaes/nvda that referenced this pull request Nov 7, 2025
nvdaes added a commit to nvdaes/nvda that referenced this pull request Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. merge-early Merge Early in a developer cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants