[orca: 1/2] Correctly display long strings of non-space characters that exceed the width of the braille line.



commit 79e3019af2d4d2e14b6eae872b6afc76d8ca1b3d
Author: Jason J.G. White <35142-jasonjgw users noreply gitlab gnome org>
Date:   Tue May 19 13:49:56 2020 +0000

    Correctly display long strings of non-space characters that exceed the
    width of the braille line.
    
    This is achieved by dividing such strings into shorter character ranges
    that fit the braille line, allowing the user to pan the display without
    skipping text. Strings such as URIs can be several multiples of the
    braille line length, especially on smaller displays.

 src/orca/braille.py         | 26 ++++++++++++++++++++++----
 src/orca/flat_review.py     |  3 +++
 src/orca/scripts/default.py | 13 +++++++++----
 3 files changed, 34 insertions(+), 8 deletions(-)
---
diff --git a/src/orca/braille.py b/src/orca/braille.py
index c9be96e39..94c4c5a62 100644
--- a/src/orca/braille.py
+++ b/src/orca/braille.py
@@ -367,8 +367,13 @@ class Region:
                             mode=mode)
 
         # Make sure the cursor is at a realistic spot.
+        # Note that if cursorOffset is beyond the end of the buffer,
+        # a spurious value is returned by liblouis in cursorPos.
         #
-        cursorPos = min(cursorPos, len(contracted))
+        if cursorOffset >= len(line):
+            cursorPos = len(contracted)
+        else:
+            cursorPos = min(cursorPos, len(contracted))
 
         return contracted, inPos, outPos, cursorPos
 
@@ -876,7 +881,19 @@ class Line:
                 ranges.append(span)
                 span = []
             if not span:
-                span = [start, end]
+                # Subdivide long words that exceed the display width.
+                wordLength = end - start
+                if wordLength > _displaySize[0]:
+                    displayWidths = wordLength // _displaySize[0]
+                    if displayWidths:
+                        for i in range(displayWidths):
+                            ranges.append([start + i * _displaySize[0], start + (i+1) * _displaySize[0]])
+                        if wordLength % _displaySize[0]:
+                            span = [start + displayWidths * _displaySize[0], end]
+                        else:
+                            continue
+                else:
+                    span = [start, end]
             else:
                 span[1] = end
             if end == focusOffset:
@@ -1142,13 +1159,14 @@ def refresh(panToCursor=True, targetCursorCell=0, getLinkMask=True, stopFlash=Tr
         msg = "BRAILLE: Adjusted targetCursorCell to: %i" % targetCursorCell
         debug.println(debug.LEVEL_INFO, msg, True)
 
-    # If there is no target cursor cell, then try to set one.  We
+    # If there is no target cursor cell and panning to cursor was
+    # requested, then try to set one.  We
     # currently only do this for text objects, and we do so by looking
     # at the last position of the caret offset and cursor cell.  The
     # primary goal here is to keep the cursor movement on the display
     # somewhat predictable.
 
-    if targetCursorCell == 0 and onSameLine:
+    if panToCursor and targetCursorCell == 0 and onSameLine:
         if lastCursorCell == 0:
             msg = "BRAILLE: Not adjusting targetCursorCell. User panned caret out of view."
             debug.println(debug.LEVEL_INFO, msg, True)
diff --git a/src/orca/flat_review.py b/src/orca/flat_review.py
index 7441df9f7..3002d6b31 100644
--- a/src/orca/flat_review.py
+++ b/src/orca/flat_review.py
@@ -901,6 +901,7 @@ class Context:
                 regionWithFocus = zone.brailleRegion
                 regionWithFocus.cursorOffset = 0
                 if zone.words:
+                    regionWithFocus.cursorOffset += zone.words[0].startOffset - zone.startOffset
                     for wordIndex in range(0, self.wordIndex):
                         regionWithFocus.cursorOffset += \
                             len(zone.words[wordIndex].string)
@@ -1162,12 +1163,14 @@ class Context:
                     self.wordIndex = 0
                     self.charIndex = 0
                     moved = True
+                    braille.clear()
                 elif wrap & Context.WRAP_TOP_BOTTOM:
                     self.lineIndex  = 0
                     self.zoneIndex  = 0
                     self.wordIndex = 0
                     self.charIndex = 0
                     moved = True
+                    braille.clear()
         elif flatReviewType == Context.CHAR:
             zone = self.lines[self.lineIndex].zones[self.zoneIndex]
             if zone.words:
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index d6bb03f1f..e114f557e 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -1126,10 +1126,10 @@ class Script(script.Script):
         if self.flatReviewContext:
             if self.isBrailleEndShowing():
                 self.flatReviewContext.goEnd(flat_review.Context.LINE)
+                # Reviewing the next character also updates the braille output and refreshes the display.
                 self.reviewNextCharacter(inputEvent)
-            else:
-                self.panBrailleInDirection(panAmount, panToLeft=False)
-
+                return
+            self.panBrailleInDirection(panAmount, panToLeft=False)
             self._setFlatReviewContextToBeginningOfBrailleDisplay()
             self.targetCursorCell = 1
             self.updateBrailleReview(self.targetCursorCell)
@@ -3543,7 +3543,12 @@ class Script(script.Script):
         # TODO - JD: Again, for now we're preserving the original behavior of choosing the first.
         region = regions[0]
         position = max(region.brailleOffset, braille.viewport[0])
-        offset = position - region.brailleOffset
+        if region.contracted:
+            offset = region.inPos[position - region.brailleOffset]
+        else:
+            offset = position - region.brailleOffset
+        if isinstance(region.zone, flat_review.TextZone):
+            offset += region.zone.startOffset
         msg = "DEFAULT: Offset for region: %i" % offset
         debug.println(debug.LEVEL_INFO, msg, True)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]