Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inaccurate text reporting in Visual Studio text controls #15838

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 19 additions & 12 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,6 @@ def findOverlayClasses(self, clsList): # NOQA: C901
):
# Bounces focus from a netUI dead placeholder menu item when no item is selected up to the menu itself.
clsList.append(PlaceholderNetUITWMenuItem)
elif UIAClassName == "WpfTextView":
clsList.append(WpfTextView)
elif (
UIAClassName == "ListViewItem"
and self.UIAElement.cachedFrameworkID == "WPF"
Expand Down Expand Up @@ -1261,6 +1259,8 @@ def findOverlayClasses(self, clsList): # NOQA: C901
if self.UIAFrameworkId == 'XAML':
# This UIA element is being exposed by the XAML framework.
clsList.append(XamlEditableText)
elif UIAClassName == "WpfTextView":
clsList.append(WpfTextView)
if UIAHandler.autoSelectDetectionAvailable:
clsList.append(EditableTextWithAutoSelectDetection)
else:
Expand Down Expand Up @@ -2213,17 +2213,16 @@ def event_UIA_dropTargetEffect(self):
ui.message(dropTargetEffect)


class XamlEditableText(EditableTextBase, UIA):
""" a UIA element with editable text exposed by the XAML framework."""
class InaccurateTextChangeEventEmittingEditableText(EditableTextBase, UIA):

# XAML fires UIA textSelectionChange events before the caret position change is reflected
# XAML and WPF fire UIA textSelectionChange events before the caret position change is reflected
# in the related UIA text pattern.
# This means that, apart from deleting text, NVDA cannot rely on textSelectionChange (caret) events in XAML
# to detect if the caret has moved, as it occurs too early.
# This means that, apart from deleting text, NVDA cannot rely on textSelectionChange (caret) events
# in XAML or WPF to detect if the caret has moved, as it occurs too early.
caretMovementDetectionUsesEvents = False

def _backspaceScriptHelper(self, unit: str, gesture: inputCore.InputGesture):
"""As UIA text range objects from XAML don't mutate with backspace,
"""As UIA text range objects from XAML or WPF don't mutate with backspace,
comparing a text range copied from before backspace with a text range fetched after backspace
isn't reliable, as the ranges compare equal.
Therefore, we must always rely on events for caret change detection in this case.
Expand All @@ -2235,6 +2234,11 @@ def _backspaceScriptHelper(self, unit: str, gesture: inputCore.InputGesture):
self.caretMovementDetectionUsesEvents = False


class XamlEditableText(InaccurateTextChangeEventEmittingEditableText):
"""An UIA element with editable text exposed by the XAML framework."""
...


class TreeviewItem(UIA):

def _get_value(self):
Expand Down Expand Up @@ -2400,17 +2404,20 @@ class ToolTip(ToolTip, UIA):
event_UIA_toolTipOpened=ToolTip.event_show


#WpfTextView fires name state changes once a second, plus when IUIAutomationTextRange::GetAttributeValue is called.
#This causes major lags when using this control with Braille in NVDA. (#2759)
#For now just ignore the events.
class WpfTextView(UIA):
class WpfTextView(InaccurateTextChangeEventEmittingEditableText):
"""WpfTextView fires name state changes once a second,
plus when IUIAutomationTextRange::GetAttributeValue is called.
This causes major lag when using this control with Braille in NVDA. (#2759)
For now just ignore the events.
"""

def event_nameChange(self):
return

def event_stateChange(self):
return


class SearchField(EditableTextWithSuggestions, UIA):
"""An edit field that presents suggestions based on a search term.
This is now an empty class as functionality has been moved to the base EditableText behaviour.
Expand Down