Skip to content

Commit

Permalink
Fix getting offsets from points in edit controls when offset numbers …
Browse files Browse the repository at this point in the history
…exceed 16 bits (#8397)

* Fix _getOffsetFromPoint for edit TextInfo

* Review action

* Add additional comments to make things clearer, hopefully

* Update what's new
  • Loading branch information
LeonarddeR authored and michaelDCurran committed Jul 18, 2018
1 parent 366bbc1 commit 0814aa7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion source/NVDAObjects/window/edit.py
Expand Up @@ -193,7 +193,25 @@ def _getOffsetFromPoint(self,x,y):
winKernel.virtualFreeEx(processHandle,internalP,0,winKernel.MEM_RELEASE)
else:
p=(x-left)+((y-top)<<16)
offset=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_CHARFROMPOS,0,p)&0xffff
res=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_CHARFROMPOS,0,p)
offset=winUser.LOWORD(res)
lineNum=winUser.HIWORD(res)
if offset==0xFFFF and lineNum==0xFFFF:
raise LookupError("Point outside client aria")
if self._getStoryLength() > 0xFFFF:
# Returned 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 start offset of the line with the retrieved line number.
lineStart=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_LINEINDEX,lineNum,0)
# Get the last 16 bits of the line number
lineStart16=lineStart&0xFFFF
if lineStart16 > offset:
# There are cases where the last 16 bits of the line start are greather than the 16 bits offset.
# For example, this happens when the line start offset is 65534 (0xFFFE)
# and the offset we need ought to be 65537 (0x10001), which is a 17 bits number
# In that case, add 0x10000 to the offset, which will make the eventual formula return the correct offset,
# unless a line has more than 65535 characters, in which case we can't get a reliable offset.
offset+=0x10000
offset = (offset - lineStart16) + lineStart
return offset

def _getCharFormat(self,offset):
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.t2t
Expand Up @@ -37,6 +37,7 @@ What's New in NVDA
- By default, ALVA BC6 displays will no longer execute emulated system keyboard keys when pressing key combinations involving sp2+sp3 to trigger internal functionality. (#8230)
- Pressing sp2 on an ALVA BC6 display to emulate the alt key now works as advertised. (#8360)
- NVDA no longer announces redundant keyboard layout changes. (#7383)
- Mouse tracking is now much more accurate in Notepad and other plain text edit controls when in a document with more than 65535 characters. (#8397)


== Changes for Developers ==
Expand Down

0 comments on commit 0814aa7

Please sign in to comment.