Skip to content

Commit

Permalink
handle more braille line updates
Browse files Browse the repository at this point in the history
  • Loading branch information
burmancomp committed Jul 27, 2023
1 parent 72545d7 commit 6a5b4d7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
10 changes: 9 additions & 1 deletion source/NVDAObjects/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
# Copyright (C) 2006-2022 NV Access Limited, Peter Vágner, Joseph Lee, Bill Dengler
# Copyright (C) 2006-2023 NV Access Limited, Peter Vágner, Joseph Lee, Bill Dengler,
# Burman's Computer and Education Ltd.

"""Mix-in classes which provide common behaviour for particular types of controls across different APIs.
Behaviors described in this mix-in include providing table navigation commands for certain table rows, terminal input and output support, announcing notifications and suggestion items and so on.
Expand Down Expand Up @@ -475,6 +476,13 @@ def _get_caretMovementDetectionUsesEvents(self):
prompt to be read when quickly deleting text."""
return False

def event_textChange(self) -> None:
"""Fired when the text changes.
@note: Updates also braille.
"""
super().event_textChange()
braille.handler.handleUpdate(self)


class EnhancedTermTypedCharSupport(Terminal):
"""A Terminal object with keyboard support enhancements for console applications.
Expand Down
33 changes: 31 additions & 2 deletions source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ def bufferPosToRegionPos(self, bufferPos):
raise LookupError("No such position")

def regionPosToBufferPos(self, region, pos, allowNearest=False):
start: int = 0
for testRegion, start, end in self.regionsWithPositions:
if region == testRegion:
if pos < end - start:
Expand Down Expand Up @@ -2052,6 +2053,8 @@ def __init__(self):
self._rawText = u""

self.queuedWriteLock = threading.Lock()
# For race condition when updating region in terminal window.
self._updateRegionLock: threading.Lock = threading.Lock()
self.ackTimerHandle = winKernel.createWaitableTimer()

brailleViewer.postBrailleViewerToolToggledAction.register(self._onBrailleViewerChangedState)
Expand Down Expand Up @@ -2487,7 +2490,14 @@ def handlePendingCaretUpdate(self):

def _doCursorMove(self, region):
self.mainBuffer.saveWindow()
region.update()
if (
hasattr(region.obj, "role")
and region.obj.role == controlTypes.Role.TERMINAL
):
with self._updateRegionLock:
region.update()
else:
region.update()
self.mainBuffer.update()
self.mainBuffer.restoreWindow()
self.scrollToCursorOrSelection(region)
Expand Down Expand Up @@ -2549,7 +2559,14 @@ def handleUpdate(self, obj: "NVDAObject") -> None:
self._handleProgressBarUpdate(obj)
return
self.mainBuffer.saveWindow()
region.update()
if (
hasattr(region.obj, "role")
and region.obj.role == controlTypes.Role.TERMINAL
):
with self._updateRegionLock:
region.update()
else:
region.update()
self.mainBuffer.update()
self.mainBuffer.restoreWindow()
if self.buffer is self.mainBuffer:
Expand Down Expand Up @@ -2686,6 +2703,17 @@ def _ackTimeoutResetter(self, param: int):
self.display._awaitingAck = False
self._writeCellsInBackground()

def updateShowSelection(self) -> None:
"""Braille needs update when braille show selection state changes."""
obj: NVDAObject
if api.isObjectInActiveTreeInterceptor(api.getNavigatorObject()):
obj = api.getCaretObject()
elif self.getTether() == TetherTo.FOCUS.value:
obj = api.getFocusObject()
else:
obj = api.getNavigatorObject()
self.handleUpdate(obj)


# Maps old braille display driver names to new drivers that supersede old drivers.
# Ensure that if a user has set a preferred driver which has changed name, the new
Expand Down Expand Up @@ -2728,6 +2756,7 @@ def terminate():
handler.terminate()
handler = None


class BrailleDisplayDriver(driverHandler.Driver):
"""Abstract base braille display driver.
Each braille display driver should be a separate Python module in the root brailleDisplayDrivers directory
Expand Down
2 changes: 2 additions & 0 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3300,6 +3300,7 @@ def script_braille_toggleShowCursor(self, gesture):
state = _("Braille cursor on")
config.conf["braille"]["showCursor"]=True
ui.message(state)
braille.handler.update()

@script(
# Translators: Input help mode message for cycle braille cursor shape command.
Expand Down Expand Up @@ -3368,6 +3369,7 @@ def script_braille_cycleShowSelection(self, gesture: inputCore.InputGesture) ->
# (disabled or enabled).
msg = _("Braille show selection %s") % BoolFlag[nextName].displayString
ui.message(msg)
braille.handler.updateShowSelection()

@script(
# Translators: Input help mode message for report clipboard text command.
Expand Down

0 comments on commit 6a5b4d7

Please sign in to comment.