Skip to content

Commit 820eb60

Browse files
authored
Merge 1f93ef5 into c5a7e68
2 parents c5a7e68 + 1f93ef5 commit 820eb60

1 file changed

Lines changed: 43 additions & 5 deletions

File tree

source/UIAHandler/__init__.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2008-2021 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter, Bill Dengler
2+
# Copyright (C) 2008-2022 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter, Bill Dengler
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

@@ -99,6 +99,13 @@
9999
"Shell_SystemDialog", # Various dialogs in Windows 10 Settings app
100100
]
101101

102+
textChangeUIAClassNames = (
103+
"_WwG",
104+
"ConsoleWindowClass",
105+
"TermControl",
106+
"TermControl2"
107+
)
108+
102109
NVDAUnitsToUIAUnits: Dict[str, int] = {
103110
textInfos.UNIT_CHARACTER: UIA.TextUnit_Character,
104111
textInfos.UNIT_WORD: UIA.TextUnit_Word,
@@ -206,11 +213,9 @@
206213
autoSelectDetectionAvailable = False
207214
if winVersion.getWinVer() >= winVersion.WIN10:
208215
UIAEventIdsToNVDAEventNames.update({
209-
UIA.UIA_Text_TextChangedEventId: "textChange",
210216
UIA.UIA_Text_TextSelectionChangedEventId: "caret",
211217
})
212218
localEventHandlerGroupUIAEventIds.update({
213-
UIA.UIA_Text_TextChangedEventId,
214219
UIA.UIA_Text_TextSelectionChangedEventId,
215220
})
216221
autoSelectDetectionAvailable = True
@@ -421,21 +426,41 @@ def _registerGlobalEventHandlers(self):
421426
def _createLocalEventHandlerGroup(self):
422427
if isinstance(self.clientObject, UIA.IUIAutomation6):
423428
self.localEventHandlerGroup = self.clientObject.CreateEventHandlerGroup()
429+
self.localEventHandlerGroupWithTextChanges = self.clientObject.CreateEventHandlerGroup()
424430
else:
425431
self.localEventHandlerGroup = utils.FakeEventHandlerGroup(self.clientObject)
432+
self.localEventHandlerGroupWithTextChanges = utils.FakeEventHandlerGroup(self.clientObject)
426433
self.localEventHandlerGroup.AddPropertyChangedEventHandler(
427434
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
428435
self.baseCacheRequest,
429436
self,
430437
*self.clientObject.IntSafeArrayToNativeArray(localEventHandlerGroupUIAPropertyIds)
431438
)
439+
self.localEventHandlerGroupWithTextChanges.AddPropertyChangedEventHandler(
440+
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
441+
self.baseCacheRequest,
442+
self,
443+
*self.clientObject.IntSafeArrayToNativeArray(localEventHandlerGroupUIAPropertyIds)
444+
)
432445
for eventId in localEventHandlerGroupUIAEventIds:
433446
self.localEventHandlerGroup.AddAutomationEventHandler(
434447
eventId,
435448
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
436449
self.baseCacheRequest,
437450
self
438451
)
452+
self.localEventHandlerGroupWithTextChanges.AddAutomationEventHandler(
453+
eventId,
454+
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
455+
self.baseCacheRequest,
456+
self
457+
)
458+
self.localEventHandlerGroupWithTextChanges.AddAutomationEventHandler(
459+
UIA.UIA_Text_TextChangedEventId,
460+
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
461+
self.baseCacheRequest,
462+
self
463+
)
439464

440465
def addEventHandlerGroup(self, element, eventHandlerGroup):
441466
if isinstance(eventHandlerGroup, UIA.IUIAutomationEventHandlerGroup):
@@ -466,7 +491,12 @@ def func():
466491
if not isStillFocus:
467492
return
468493
try:
469-
self.addEventHandlerGroup(element, self.localEventHandlerGroup)
494+
group = (
495+
self.localEventHandlerGroupWithTextChanges
496+
if element.currentClassName in textChangeUIAClassNames
497+
else self.localEventHandlerGroup
498+
)
499+
self.addEventHandlerGroup(element, group)
470500
except COMError:
471501
log.error("Could not register for UIA events for element", exc_info=True)
472502
else:
@@ -500,7 +530,15 @@ def IUIAutomationEventHandler_HandleAutomationEvent(self,sender,eventID):
500530
if _isDebug():
501531
log.debug("HandleAutomationEvent: Ignored MenuOpenedEvent while focus event pending")
502532
return
503-
NVDAEventName=UIAEventIdsToNVDAEventNames.get(eventID,None)
533+
if eventID == UIA.UIA_Text_TextChangedEventId:
534+
if sender.currentClassName in textChangeUIAClassNames:
535+
NVDAEventName = "textChange"
536+
else:
537+
if _isDebug():
538+
log.debugWarning(f"HandleAutomationEvent: Dropping unused textChange event")
539+
return
540+
else:
541+
NVDAEventName = UIAEventIdsToNVDAEventNames.get(eventID, None)
504542
if not NVDAEventName:
505543
if _isDebug():
506544
log.debugWarning(f"HandleAutomationEvent: Don't know how to handle event {eventID}")

0 commit comments

Comments
 (0)