Repository: nvaccess/nvda

Issue:
NVDA's support for Scintilla controls. is broken in alpha snapshots, if "line wrap" is enabled in the text editor
### Steps to reproduce:
1. Install a text editor like Notepad++.
2. In it, open a text file containing a few lines of text.
3. Enable the text editor's "line wrap" feature.
4. Start reading line by line with the up/down arrow keys.
5. Enable NVDA's mouse tracking and use the mouse to hover over and read the separate lines of text.

### Actual behavior:
With the up/down arrow keys, NVDA reads another line of text and not the one on which the cursor is positioned. This behavior affects only reading line by line - reading by word or character seams to be working as expected. The situation when reading with the mouse is similar - NVDA does not read the line which the mouse is pointing, but another one. And this occurs only if the "line wrap" feature of the text editor is enabled, so long lines of text are wrapped on multiple lines if necessary.

### Expected behavior:
NVDA should read the line on which the cursor is positioned or the one which the mouse is pointing, even if the "line wrap" feature of the text editor is enabled.

### System configuration
- Operating system: Windows 10 Pro version 1809 (build 17763.379), 64-bit, in Bulgarian with all locale settings set to "Bulgarian".
- NVDA version: alpha-16976,7fc6c71f.
- Processor: Intel Core i5-4670 at 3.40GHz.
- RAM Memory: 8.00GB.
- Graphics: MSI GeForce GTX-1050TI Gaming X 4G, 4096MB dedicated memory + 4065MB shared system memory, desktop resolution set to 1920x1080.
- Sound Card: Realtek ALC887 at Intel Lynx Point PCH - High Definition Audio Controller.

### Other questions
#### Does the issue still occur after restarting your PC?
Yes, it does.

#### Have you tried any other versions of NVDA?
No, because this started occurring only with the latest "alpha" snapshots of NVDA. I guess this is probably caused by #9233 (Fixing incorrect text reporting when hovering mouse over Scintilla controls), though I might be wrong.


Discussion:
CC @DataTriny, this is probably caused by #9233. Could you please investigate as soon as possible what might causing this?
reproducable by me, it also messes up the text shown on braille displays as well if thats of any help, tested with a Baum braille display addressed via Baum drivers.

Resolving patch:
diff --git a/source/NVDAObjects/window/scintilla.py b/source/NVDAObjects/window/scintilla.py
--- a/source/NVDAObjects/window/scintilla.py
+++ b/source/NVDAObjects/window/scintilla.py
@@ -70,10 +70,11 @@ def _getOffsetFromPoint(self,x,y):
 		return watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POSITIONFROMPOINT,x,y)
 
 	def _getPointFromOffset(self,offset):
-		point=textInfos.Point(
-		watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POINTXFROMPOSITION,None,offset),
-		watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POINTYFROMPOSITION,None,offset)
+		x, y = winUser.ClientToScreen(self.obj.windowHandle,
+			watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POINTXFROMPOSITION,None,offset),
+			watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POINTYFROMPOSITION,None,offset)
 		)
+		point=textInfos.Point(x, y)
 		if point.x is not None and point.y is not None:
 			return point
 		else:
@@ -192,10 +193,10 @@ def _getLineOffsets(self,offset):
 		if watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_GETWRAPMODE,None,None)!=SC_WRAP_NONE:
 			# Lines in Scintilla refer to document lines, not wrapped lines.
 			# There's no way to retrieve wrapped lines, so use screen coordinates.
-			y=watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POINTYFROMPOSITION,None,offset)
-			top,left,width,height=self.obj.location
-			start = self._getOffsetFromPoint(0,y)
-			end=self._getOffsetFromPoint(width,y)
+			y = self._getPointFromOffset(offset).y
+			location=self.obj.location
+			start = self._getOffsetFromPoint(location.left, y)
+			end=self._getOffsetFromPoint(location.right, y)
 			# If this line wraps to the next line,
 			# end is the first offset of the next line.
 			if watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POINTYFROMPOSITION,None,end)==y:


Test patch: