Skip to content

Fix getting offsets from points in edit controls when offset numbers exceed 16 bits#8397

Merged
michaelDCurran merged 5 commits into
nvaccess:masterfrom
BabbageCom:editOffsetFromPoint
Jul 18, 2018
Merged

Fix getting offsets from points in edit controls when offset numbers exceed 16 bits#8397
michaelDCurran merged 5 commits into
nvaccess:masterfrom
BabbageCom:editOffsetFromPoint

Conversation

@LeonarddeR

@LeonarddeR LeonarddeR commented Jun 14, 2018

Copy link
Copy Markdown
Collaborator

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:

Comment thread 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

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.

Space after =

Comment thread 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)

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.

What is contained in the LOWORD? Could the variable name make this clear?

# Get the last 16 bits of the line number
lineStart16=lineStart&0xFFFF
if lineStart16 > offset:
offset+=0x10000

Copy link
Copy Markdown
Member

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?

michaelDCurran
michaelDCurran previously approved these changes Jun 18, 2018
@michaelDCurran michaelDCurran merged commit 0814aa7 into nvaccess:master Jul 18, 2018
@nvaccessAuto nvaccessAuto added this to the 2018.3 milestone Jul 18, 2018
@LeonarddeR LeonarddeR added the BabbageWork Pull requests filed on behalf of Babbage B.V. label Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BabbageWork Pull requests filed on behalf of Babbage B.V.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants