[orca/gnome-3-34] Improve performance of text selection in web content



commit 5937dbd05002a7b54a793761a9b4a02cf6486f5d
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Thu Sep 26 18:54:51 2019 +0200

    Improve performance of text selection in web content

 src/orca/scripts/web/script_utilities.py | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index d9e3dee17..877d5e58b 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -25,6 +25,7 @@ __copyright__ = "Copyright (c) 2010 Joanmarie Diggs." \
                 "Copyright (c) 2014-2015 Igalia, S.L."
 __license__   = "LGPL"
 
+import functools
 import pyatspi
 import re
 import time
@@ -1754,18 +1755,25 @@ class Utilities(script_utilities.Utilities):
         if not self.inDocumentContent(obj):
             return super().handleTextSelectionChange(obj)
 
-        if self.hasPresentableText(obj) and super().handleTextSelectionChange(obj, speakMessage):
-            return True
+        oldStart, oldEnd = self._script.pointOfReference.get('selectionAnchorAndFocus', (None, None))
+        start, end = self._getSelectionAnchorAndFocus(obj)
+        self._script.pointOfReference['selectionAnchorAndFocus'] = (start, end)
+
+        oldSubtree = self._getSubtree(oldStart, oldEnd)
+        newSubtree = self._getSubtree(start, end)
 
-        handled = False
-        descendants = self.findAllDescendants(obj, self.hasPresentableText)
+        def _cmp(obj1, obj2):
+            return self.pathComparison(pyatspi.getPath(obj1), pyatspi.getPath(obj2))
+
+        descendants = sorted(set(oldSubtree).union(newSubtree), key=functools.cmp_to_key(_cmp))
         for descendant in descendants:
-            if handled:
+            if descendant not in (oldStart, oldEnd, start, end) \
+               and pyatspi.findAncestor(descendant, lambda x: x in descendants):
                 super().updateCachedTextSelection(descendant)
             else:
-                handled = super().handleTextSelectionChange(descendant, speakMessage)
+                super().handleTextSelectionChange(descendant, speakMessage)
 
-        return handled
+        return True
 
     def inPDFViewer(self, obj=None):
         uri = self.documentFrameURI()


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