Skip to content

Commit cfa6189

Browse files
authored
Merge b371911 into e6e443b
2 parents e6e443b + b371911 commit cfa6189

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

source/NVDAObjects/window/excel.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2006-2023 NV Access Limited, Dinesh Kaushal, Siddhartha Gupta, Accessolutions, Julien Cochuyt,
2+
# Copyright (C) 2006-2025 NV Access Limited, Dinesh Kaushal, Siddhartha Gupta, Accessolutions, Julien Cochuyt,
33
# Cyrille Bougot, Leonard de Ruijter
44
# This file is covered by the GNU General Public License.
55
# See the file COPYING for more details.
66

7+
from __future__ import annotations
78
import abc
89
import ctypes
910
import enum
1011
from typing import (
1112
Any,
1213
Dict,
1314
Optional,
15+
Callable,
1416
)
1517

1618
from comtypes import COMError, BSTR
@@ -795,6 +797,15 @@ def _getDropdown(self, selection=None):
795797
obj.parent = selection
796798
return obj
797799

800+
def _getActiveCell(self) -> "ExcelCell":
801+
cell = self.excelWindowObject.ActiveCell
802+
obj = ExcelCell(
803+
windowHandle=self.windowHandle,
804+
excelWindowObject=self.excelWindowObject,
805+
excelCellObject=cell,
806+
)
807+
return obj
808+
798809
def _getSelection(self):
799810
selection = self.excelWindowObject.Selection
800811
try:
@@ -1094,6 +1105,17 @@ def _get_states(self):
10941105
"kb:numpadEnter",
10951106
"kb:shift+enter",
10961107
"kb:shift+numpadEnter",
1108+
),
1109+
canPropagate=True,
1110+
)
1111+
def script_changeActiveCell(self, gesture: inputCore.InputGesture) -> None:
1112+
self.changeSelectionOrActiveCell(
1113+
gesture=gesture,
1114+
objGetter=self._getActiveCell,
1115+
)
1116+
1117+
@scriptHandler.script(
1118+
gestures=(
10971119
"kb:upArrow",
10981120
"kb:downArrow",
10991121
"kb:leftArrow",
@@ -1140,8 +1162,18 @@ def _get_states(self):
11401162
),
11411163
canPropagate=True,
11421164
)
1143-
def script_changeSelection(self, gesture):
1144-
oldSelection = self._getSelection()
1165+
def script_changeSelection(self, gesture: inputCore.InputGesture) -> None:
1166+
self.changeSelectionOrActiveCell(
1167+
gesture=gesture,
1168+
objGetter=self._getSelection,
1169+
)
1170+
1171+
def changeSelectionOrActiveCell(
1172+
self,
1173+
gesture: inputCore.InputGesture,
1174+
objGetter: Callable[[], ExcelCell | ExcelSelection | _msOfficeChart.OfficeChart],
1175+
):
1176+
oldSelection = objGetter()
11451177
gesture.send()
11461178
newSelection = None
11471179
start = time.time()
@@ -1157,7 +1189,7 @@ def script_changeSelection(self, gesture):
11571189
if eventHandler.isPendingEvents("gainFocus"):
11581190
# This object is no longer focused.
11591191
return
1160-
newSelection = self._getSelection()
1192+
newSelection = objGetter()
11611193
if newSelection and newSelection != oldSelection:
11621194
log.debug(f"Detected new selection after {elapsed} sec")
11631195
break

0 commit comments

Comments
 (0)