[orca: 1/2] Fix braille updating when backspacing text on long lines



commit e758beabf9dee604be353230f9d5e5ed3a98ae2b
Author: Samuel Thibault <samuel thibault ens-lyon org>
Date:   Fri Jun 29 10:48:34 2018 +0000

    Fix braille updating when backspacing text on long lines

 src/orca/braille.py                      | 13 ++++++++++---
 src/orca/scripts/default.py              | 24 ++++++++++++------------
 src/orca/scripts/web/script_utilities.py | 16 ++++++++++------
 3 files changed, 32 insertions(+), 21 deletions(-)
---
diff --git a/src/orca/braille.py b/src/orca/braille.py
index 88a6cf6c3..335272c1a 100644
--- a/src/orca/braille.py
+++ b/src/orca/braille.py
@@ -585,9 +585,11 @@ class Text(Region):
         True.  Otherwise, return False.
         """
 
+        if not _regionWithFocus:
+            return False
+
         [string, caretOffset, lineOffset] = \
-                 orca_state.activeScript.getTextLineAtCaret(self.accessible,
-                                                            self.startOffset)
+                 orca_state.activeScript.getTextLineAtCaret(self.accessible)
 
         cursorOffset = min(caretOffset - lineOffset, len(string))
 
@@ -1175,7 +1177,7 @@ def refresh(panToCursor=True,
     # right of the display if we need to pan right.
     #
     if panToCursor and (cursorOffset >= 0):
-        if len(string) <= _displaySize[0]:
+        if cursorOffset < _displaySize[0]:
             viewport[0] = 0
         elif targetCursorCell:
             viewport[0] = max(0, cursorOffset - targetCursorCell + 1)
@@ -1186,6 +1188,8 @@ def refresh(panToCursor=True,
         else:
             rangeForOffset = _getRangeForOffset(cursorOffset)
             viewport[0] = max(0, rangeForOffset[0])
+            if cursorOffset >= (viewport[0] + _displaySize[0]):
+                viewport[0] = max(0, cursorOffset - _displaySize[0] + 1)
 
     startPos, endPos = _adjustForWordWrap()
     viewport[0] = startPos
@@ -1434,6 +1438,9 @@ def _getRangeForOffset(offset):
     for r in ranges:
         if r[0] <= offset < r[1]:
             return r
+    for r in ranges:
+        if offset == r[1]:
+            return r
 
     return [0, 0]
 
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 1a646e992..396572bcc 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -3598,7 +3598,10 @@ class Script(script.Script):
         except NotImplementedError:
             return ["", 0, 0]
 
-        # The caret might be positioned at the very end of the text area.
+        if startOffset is None:
+            startOffset = max(0, text.caretOffset)
+
+        # The offset might be positioned at the very end of the text area.
         # In these cases, calling text.getTextAtOffset on an offset that's
         # not positioned to a character can yield unexpected results.  In
         # particular, we'll see the Gecko toolkit return a start and end
@@ -3612,17 +3615,15 @@ class Script(script.Script):
         # to see if that character is a newline - if it is, we'll treat it
         # as the line.
         #
-        if text.caretOffset == text.characterCount:
-            caretOffset = max(0, text.caretOffset - 1)
-            character = text.getText(caretOffset, caretOffset + 1)
+        if startOffset == text.characterCount:
+            startOffset = max(0, startOffset - 1)
+            character = text.getText(startOffset, startOffset + 1)
         else:
-            caretOffset = text.caretOffset
             character = None
 
-        if (text.caretOffset == text.characterCount) \
+        if (startOffset == text.characterCount) \
             and (character == "\n"):
             lineString = ""
-            startOffset = caretOffset
         else:
             # Get the line containing the caret.  [[[TODO: HACK WDW - If
             # there's only 1 character in the string, well, we get it.  We
@@ -3630,14 +3631,13 @@ class Script(script.Script):
             # is broken if there is just one character in the string.]]]
             #
             if (text.characterCount == 1):
-                lineString = text.getText(caretOffset, caretOffset + 1)
-                startOffset = caretOffset
+                lineString = text.getText(startOffset, startOffset + 1)
             else:
-                if caretOffset == -1:
-                    caretOffset = text.characterCount
+                if startOffset == -1:
+                    startOffset = text.characterCount
                 try:
                     [lineString, startOffset, endOffset] = text.getTextAtOffset(
-                        caretOffset, pyatspi.TEXT_BOUNDARY_LINE_START)
+                        startOffset, pyatspi.TEXT_BOUNDARY_LINE_START)
                 except:
                     return ["", 0, 0]
 
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index a9ec6eeff..c982e4a4f 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -792,7 +792,7 @@ class Utilities(script_utilities.Utilities):
 
         return attrs
 
-    def findObjectInContents(self, obj, offset, contents):
+    def findObjectInContents(self, obj, offset, contents, usingCache=False):
         if not obj or not contents:
             return -1
 
@@ -801,6 +801,10 @@ class Utilities(script_utilities.Utilities):
         match = [x for x in matches if x[1] <= offset < x[2]]
         if match and match[0] and match[0] in contents:
             return contents.index(match[0])
+        if not usingCache:
+            match = [x for x in matches if offset == x[2]]
+            if match and match[0] and match[0] in contents:
+                return contents.index(match[0])
 
         if not self.isTextBlockElement(obj):
             return -1
@@ -1113,7 +1117,7 @@ class Utilities(script_utilities.Utilities):
         offset = max(0, offset)
 
         if useCache:
-            if self.findObjectInContents(obj, offset, self._currentSentenceContents) != -1:
+            if self.findObjectInContents(obj, offset, self._currentSentenceContents, usingCache=True) != -1:
                 return self._currentSentenceContents
 
         boundary = pyatspi.TEXT_BOUNDARY_SENTENCE_START
@@ -1181,7 +1185,7 @@ class Utilities(script_utilities.Utilities):
         offset = max(0, offset)
 
         if useCache:
-            if self.findObjectInContents(obj, offset, self._currentCharacterContents) != -1:
+            if self.findObjectInContents(obj, offset, self._currentCharacterContents, usingCache=True) != -1:
                 return self._currentCharacterContents
 
         boundary = pyatspi.TEXT_BOUNDARY_CHAR
@@ -1198,7 +1202,7 @@ class Utilities(script_utilities.Utilities):
         offset = max(0, offset)
 
         if useCache:
-            if self.findObjectInContents(obj, offset, self._currentWordContents) != -1:
+            if self.findObjectInContents(obj, offset, self._currentWordContents, usingCache=True) != -1:
                 return self._currentWordContents
 
         boundary = pyatspi.TEXT_BOUNDARY_WORD_START
@@ -1268,7 +1272,7 @@ class Utilities(script_utilities.Utilities):
         offset = max(0, offset)
 
         if useCache:
-            if self.findObjectInContents(obj, offset, self._currentObjectContents) != -1:
+            if self.findObjectInContents(obj, offset, self._currentObjectContents, usingCache=True) != -1:
                 return self._currentObjectContents
 
         objIsLandmark = self.isLandmark(obj)
@@ -1329,7 +1333,7 @@ class Utilities(script_utilities.Utilities):
         offset = max(0, offset)
 
         if useCache:
-            if self.findObjectInContents(obj, offset, self._currentLineContents) != -1:
+            if self.findObjectInContents(obj, offset, self._currentLineContents, usingCache=True) != -1:
                 return self._currentLineContents
 
         if layoutMode is None:


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