Skip to content

Commit 4452b74

Browse files
authored
Merge 150be44 into 8cbdb79
2 parents 8cbdb79 + 150be44 commit 4452b74

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

source/appModules/devenv.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# A part of NonVisual Desktop Access (NVDA)
22
# This file is covered by the GNU General Public License.
33
# See the file COPYING for more details.
4-
# Copyright (C) 2010-2019 NV Access Limited, Soronel Haetir, Babbage B.V., Francisco Del Roio
4+
# Copyright (C) 2010-2022 NV Access Limited, Soronel Haetir, Babbage B.V., Francisco Del Roio,
5+
# Leonard de Ruijter
56

67
import objbase
78
import comtypes
@@ -14,11 +15,12 @@
1415
from comtypes.automation import IDispatch
1516
from NVDAObjects.window import DisplayModelEditableText
1617
from NVDAObjects.IAccessible import IAccessible
17-
from NVDAObjects.UIA import UIA
18+
from NVDAObjects.UIA import UIA, WpfTextView, UIATextInfo
1819
from enum import IntEnum
1920
import appModuleHandler
2021
import controlTypes
2122
import threading
23+
import UIAHandler
2224

2325

2426
# A few helpful constants
@@ -43,9 +45,12 @@ def __init__(self, *args, **kwargs):
4345
self.vsMajor, self.vsMinor = int(vsMajor), int(vsMinor)
4446

4547
def chooseNVDAObjectOverlayClasses(self, obj, clsList):
48+
if WpfTextView in clsList:
49+
clsList.remove(WpfTextView)
50+
clsList.insert(0, VsWpfTextView)
4651
# Only use this overlay class if the top level automation object for the IDE can be retrieved,
4752
# as it will not work otherwise.
48-
if obj.windowClassName == "VsTextEditPane" and self.DTE:
53+
elif obj.windowClassName == "VsTextEditPane" and self.DTE:
4954
try:
5055
clsList.remove(DisplayModelEditableText)
5156
except ValueError:
@@ -82,6 +87,44 @@ def _get_DTE(self):
8287
return DTE
8388

8489

90+
class VsWpfTextViewTextInfo(UIATextInfo):
91+
92+
def _getLineNumberString(self, textRange):
93+
# Visual Studio exposes line numbers as part of the actual text.
94+
# We want to store the line number in a format field instead.
95+
lineNumberRange = textRange.Clone()
96+
lineNumberRange.MoveEndpointByRange(
97+
UIAHandler.TextPatternRangeEndpoint_End,
98+
lineNumberRange,
99+
UIAHandler.TextPatternRangeEndpoint_Start
100+
)
101+
return lineNumberRange.GetText(-1)
102+
103+
def _getFormatFieldAtRange(self, textRange, formatConfig, ignoreMixedValues=False):
104+
formatField = super()._getFormatFieldAtRange(textRange, formatConfig, ignoreMixedValues=ignoreMixedValues)
105+
if not formatField or not formatConfig['reportLineNumber']:
106+
return formatField
107+
lineNumberStr = self._getLineNumberString(textRange)
108+
if lineNumberStr:
109+
try:
110+
formatField.field['line-number'] = int(lineNumberStr)
111+
except ValueError:
112+
log.debugWarning(
113+
f"Couldn't parse {lineNumberStr} as integer to report a line number",
114+
exc_info=True
115+
)
116+
return formatField
117+
118+
def _getTextFromUIARange(self, textRange):
119+
text = super()._getTextFromUIARange(textRange)
120+
lineNumberStr = self._getLineNumberString(textRange)
121+
return text[(0 if not lineNumberStr else len(lineNumberStr)):]
122+
123+
124+
class VsWpfTextView(WpfTextView):
125+
TextInfo = VsWpfTextViewTextInfo
126+
127+
85128
class VsTextEditPaneTextInfo(textInfos.offsets.OffsetsTextInfo):
86129

87130
def _get__selectionObject(self):

user_docs/en/changes.t2t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ What's New in NVDA
3131
- When reading non-interactive PDFs in Adobe Reader, the type and state of form fields (such as checkboxes and radio buttons) are now reported. (#13285)
3232
- "Reset configuration to factory defaults" is now accessible in the NVDA menu during secure mode. (#13547)
3333
- Any locked mouse keys will be unlocked when NVDA exits, previously the mouse button would remain locked. (#13410)
34+
- Visual Studio now reports line numbers. (#13604)
35+
- Note that for line number reporting to work, showing line numbers must be enabled in Visual Studio and NVDA.
36+
-
37+
- Visual Studio now correctly reports line indentation. (#13574)
3438
- NVDA can now beep or speak on Java application progress bars (#13594)
3539
-
3640

0 commit comments

Comments
 (0)