[orca: 1/2] Fix backspacing text



commit 93dae3f2c50cebb294af1b424d1adb49bd6acae6
Author: Samuel Thibault <samuel thibault ens-lyon org>
Date:   Tue Jun 26 18:21:05 2018 +0000

    Fix backspacing text

 src/orca/braille.py                      | 15 +++++++++++----
 src/orca/scripts/default.py              | 26 ++++++++++++++------------
 src/orca/scripts/web/script_utilities.py | 16 ++++++++++------
 3 files changed, 35 insertions(+), 22 deletions(-)
---
diff --git a/src/orca/braille.py b/src/orca/braille.py
index 88a6cf6c3..c4aa0a900 100644
--- a/src/orca/braille.py
+++ b/src/orca/braille.py
@@ -530,7 +530,7 @@ class Text(Region):
         if orca_state.activeScript and self.accessible:
             [string, self.caretOffset, self.lineOffset] = \
                  orca_state.activeScript.getTextLineAtCaret(
-                     self.accessible, startOffset=startOffset, endOffset=endOffset)
+                     self.accessible, offset=startOffset, startOffset=startOffset, endOffset=endOffset)
         else:
             string = ""
             self.caretOffset = 0
@@ -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 6b025ccd2..eb1b14d95 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -3591,7 +3591,10 @@ class Script(script.Script):
         except NotImplementedError:
             return ["", 0, 0]
 
-        # The caret might be positioned at the very end of the text area.
+        if offset is None:
+            offset = 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
@@ -3605,17 +3608,16 @@ 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 offset == text.characterCount:
+            offset = max(0, offset - 1)
+            character = text.getText(offset, offset + 1)
         else:
-            caretOffset = text.caretOffset
             character = None
 
-        if (text.caretOffset == text.characterCount) \
+        if (offset == text.characterCount) \
             and (character == "\n"):
             lineString = ""
-            startOffset = caretOffset
+            startOffset = offset
         else:
             # Get the line containing the caret.  [[[TODO: HACK WDW - If
             # there's only 1 character in the string, well, we get it.  We
@@ -3623,14 +3625,14 @@ 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(offset, offset + 1)
+                startOffset = offset
             else:
-                if caretOffset == -1:
-                    caretOffset = text.characterCount
+                if offset == -1:
+                    offset = text.characterCount
                 try:
                     [lineString, startOffset, endOffset] = text.getTextAtOffset(
-                        caretOffset, pyatspi.TEXT_BOUNDARY_LINE_START)
+                        offset, 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]