Skip to content

Commit e810276

Browse files
Merge 33caf1c into bfdd2e5
2 parents bfdd2e5 + 33caf1c commit e810276

5 files changed

Lines changed: 48 additions & 27 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: 20 additions & 11 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 is not available 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()
2055-
except NotImplementedError:
2056-
pass
2061+
except (NotImplementedError, COMError):
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."""

0 commit comments

Comments
 (0)