Skip to content

Commit 8228ae3

Browse files
michaelDCurranAdriani90
authored andcommitted
Several fixes to native selection mode (nvaccess#16129)
Fixes nvaccess#16064 Fixes nvaccess#16097 Summary of the issue: Native selection mode can be enabled in unsupported Gecko, such as Thunderbird 115.x nvaccess#16064: turning on native selection mode in thunderbird 115 would cause errors when moving with the arrow keys as IAccessibleTextSelectionContainer is unavailable. Wrong message reported when toggling native selection in Word nvaccess#16097: NVDA is misleading in MS Word browse mode when it says that native selection mode is not supported when trying to toggle it on, as MS word Browse mode does move the caret / selection, thus it has always used native selection mode.. It is just you can't toggle it off. Description of user facing changes In firefox, If NVDA fails to update the native selection when turning on native selection mode, it is now left off, and the user is notified that native selection mode is not supported. this stops errors when moving with the arrow keys in Thunderbird after turning on native selection mode. NVDA no longer incorrectly alerts the user that native selection mode is not supported in Microsoft Word. Rather, the message state that it canot be turned off. when copying text with control+c in Microsoft Word with Browse mode on, formatting is now also copied, fulfilling the expectation of a native selection mode. Description of development approach Gecko virtualBuffer's updateAppSelection method: if the selection is collapsed, don't try fetching information for the selection, instead just clear the app selection. This error was previously silently ignored. In UIA Browse mode documents, _nativeAppSelectionMode is now set to True, as this correctly reflects that UIA browse mode documents move the native selection. BrowseMode document's toggleNativeSelectionMode script: Tailor the message reported if native selection mode is not supported (by looking at _nativeSelectionMode). If _nativeSelectionMode is True, then the message is changed to state it can't be turned off. If updateappSelection fails when turning on native selection mode, log the error, turn it off, and alert the user that it is not supported. In MS word, suppress the "copy" UIA notification, if in MS word Browse mode. Otherwise there would be double speaking along with the message in cursorManager's copyToclipboard script when doing a native copy.
1 parent 35268bf commit 8228ae3

6 files changed

Lines changed: 48 additions & 26 deletions

File tree

‎source/NVDAObjects/UIA/web.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def HeadingControlQuicknavIterator(itemType, document, position, direction="next
487487

488488
class UIAWebTreeInterceptor(cursorManager.ReviewCursorManager, UIABrowseModeDocument):
489489
TextInfo = UIABrowseModeDocumentTextInfo
490+
_nativeAppSelectionMode = False
490491

491492
def makeTextInfo(self, position):
492493
try:

‎source/NVDAObjects/UIA/wordDocument.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,12 @@ def event_UIA_notification(self, activityId=None, **kwargs):
554554
# such as "delete back word" when Control+Backspace is pressed.
555555
if activityId == "AccSN2": # Delete activity ID
556556
return
557+
# copy to clipboard
558+
if activityId == 'AccSN3':
559+
ti = self.treeInterceptor
560+
if ti and not ti.passThrough:
561+
# Browse mode provides its own copy to clipboard message.
562+
return
557563
super(WordDocument, self).event_UIA_notification(**kwargs)
558564

559565
# The following overide of the EditableText._caretMoveBySentenceHelper private method

‎source/UIAHandler/browseMode.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ class UIABrowseModeDocument(UIADocumentWithTableNavigation,browseMode.BrowseMode
373373
# UIA browseMode documents cannot remember caret positions across loads (I.e. when going back a page in Edge)
374374
# Because UIA TextRanges are opaque and are tied specifically to one particular document.
375375
shouldRememberCaretPositionAcrossLoads=False
376+
_nativeAppSelectionMode = True
376377

377378
def event_UIA_activeTextPositionChanged(self, obj, nextHandler, textRange=None):
378379
if not self.isReady:

‎source/browseMode.py‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,21 +2036,30 @@ def clearAppSelection(self):
20362036
)
20372037
def script_toggleNativeAppSelectionMode(self, gesture: inputCore.InputGesture):
20382038
if not self._nativeAppSelectionModeSupported:
2039-
# Translators: the message when native selection mode is not available in this browse mode document.
2040-
ui.message(_("Native selection mode unsupported in this document"))
2039+
if not self._nativeAppSelectionMode:
2040+
# Translators: the message when native selection mode is not available in this browse mode document.
2041+
ui.message(_("Native selection mode unsupported in this browse mode document"))
2042+
else:
2043+
# Translators: the message when native selection mode cannot be turned off in this browse mode document.
2044+
ui.message(_("Native selection mode cannot be turned off in this browse mode document"))
20412045
return
2042-
self._nativeAppSelectionMode = not self._nativeAppSelectionMode
2043-
if self._nativeAppSelectionMode:
2044-
# Translators: reported when native selection mode is toggled on.
2045-
ui.message(_("Native app selection mode enabled."))
2046+
nativeAppSelectionModeOn = not self._nativeAppSelectionMode
2047+
if nativeAppSelectionModeOn:
20462048
try:
20472049
self.updateAppSelection()
20482050
except NotImplementedError:
2049-
pass
2051+
log.debugWarning("updateAppSelection failed", exc_info=True)
2052+
# Translators: the message when native selection mode is not available in this browse mode document.
2053+
ui.message(_("Native selection mode unsupported in this document"))
2054+
return
2055+
self._nativeAppSelectionMode = True
2056+
# Translators: reported when native selection mode is toggled on.
2057+
ui.message(_("Native app selection mode enabled"))
20502058
else:
2051-
# Translators: reported when native selection mode is toggled off.
2052-
ui.message(_("Native app selection mode disabled."))
20532059
try:
20542060
self.clearAppSelection()
20552061
except NotImplementedError:
2056-
pass
2062+
log.debugWarning("clearAppSelection failed", exc_info=True)
2063+
self._nativeAppSelectionMode = False
2064+
# Translators: reported when native selection mode is toggled off.
2065+
ui.message(_("Native app selection mode disabled"))

‎source/virtualBuffers/gecko_ia2.py‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -699,22 +699,26 @@ def updateAppSelection(self):
699699
except COMError as e:
700700
raise NotImplementedError from e
701701
selInfo = self.makeTextInfo(textInfos.POSITION_SELECTION)
702-
selFields = selInfo.getTextWithFields()
703-
ia2Sel = _Ia2Selection()
704-
705-
log.debug("checking fields...")
706-
self._getStartSelection(ia2Sel, selFields)
707-
self._getEndSelection(ia2Sel, selFields)
708-
709-
log.debug("setting selection...")
710-
r = IA2TextSelection(
711-
ia2Sel.startObj,
712-
ia2Sel.startOffset,
713-
ia2Sel.endObj,
714-
ia2Sel.endOffset,
715-
False
716-
)
717-
paccTextSelectionContainer.SetSelections(1, byref(r))
702+
if not selInfo.isCollapsed:
703+
selFields = selInfo.getTextWithFields()
704+
ia2Sel = _Ia2Selection()
705+
706+
log.debug("checking fields...")
707+
self._getStartSelection(ia2Sel, selFields)
708+
self._getEndSelection(ia2Sel, selFields)
709+
710+
log.debug("setting selection...")
711+
r = IA2TextSelection(
712+
ia2Sel.startObj,
713+
ia2Sel.startOffset,
714+
ia2Sel.endObj,
715+
ia2Sel.endOffset,
716+
False
717+
)
718+
paccTextSelectionContainer.SetSelections(1, byref(r))
719+
else: # No selection
720+
r = IA2TextSelection(None, 0, None, 0, False)
721+
paccTextSelectionContainer.SetSelections(0, byref(r))
718722

719723
def clearAppSelection(self):
720724
"""Clear the native selection in the application."""

‎user_docs/en/changes.t2t‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Windows 8.1 is the minimum Windows version supported.
7777
- A new Native Selection mode (toggled by ``NVDA+shift+f10``) is now available in NVDA's browse mode for Mozilla Firefox.
7878
When turned on, selecting text in browse mode will also manipulate Firefox's own native selection.
7979
Copying text with ``control+c`` will pass straight through to Firefox, thus copying the rich content, rather than NVDA's plain text representation. (#15830)
80+
- When copying text in Microsoft Word with NVDA's browse mode enabled, formatting is now also included. (#16129)
8081
- A new "on-demand" speech mode has been added.
8182
When speech is on-demand, NVDA does not speak automatically (e.g. when moving the cursor) but still speaks when calling commands whose goal is explicitly to report something (e.g. report window title). (#481, @CyrilleB79)
8283
- In the Speech category of NVDA's settings, it is now possible to exclude unwanted speech modes from the Cycle speech modes command (``NVDA+s``). (#15806, @lukaszgo1)

0 commit comments

Comments
 (0)