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
Fix getting offsets from points in edit controls when offset numbers exceed 16 bits #8397
Fix getting offsets from points in edit controls when offset numbers exceed 16 bits #8397
Conversation
eb90ec7
to
f83f193
Compare
source/NVDAObjects/window/edit.py
Outdated
lineStart=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_LINEINDEX,lineNum,0) | ||
lineStartLW = winUser.LOWORD(lineStart) | ||
if lineStartLW > offset: | ||
offset+= 0x10000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after =
source/NVDAObjects/window/edit.py
Outdated
# Offsets are 16 bits, therefore for large documents, we need to make sure that the correct offset is returned. | ||
# We can calculate this by using the line number. | ||
lineStart=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_LINEINDEX,lineNum,0) | ||
lineStartLW = winUser.LOWORD(lineStart) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is contained in the LOWORD? Could the variable name make this clear?
source/NVDAObjects/window/edit.py
Outdated
# Get the last 16 bits of the line number | ||
lineStart16=lineStart&0xFFFF | ||
if lineStart16 > offset: | ||
offset+=0x10000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you better explain what these two lines do?
Link to issue number:
None
Summary of the issue:
When getting an offset from a point in edit controls, such as notepad, a 32 bit value is returned which contains the offset in the LOWORD and the line number in the HIWORD. UNtil now, NVDA was only using the LOWORD value, which caused issues when the associated offset was higher than 65535 or 0xFFFF.
Description of how this pull request fixes the issue:
When the length of the text control exceeds 0xffff, we can't simply return the LOWORD of the EM_CHARFROMPOS result, as that might be wrong. Instead, we get the start offset that is associated with the line number and calculate the real offset for the given point based on that start offset.
Testing performed:
Tested getOffsetFromPoint behavior in Notepad. I also tested Wordpad with the text info forced to EditTextInfo. That code shouldn't have been touched, and it indeed returned the correct result as well.
Furthermore, I covered the case where for example the line start offset would be <= 0xffff whereas the offset belonging to the point ought to be greater than 0xffff.
Change log entry: