[orca] Speak text indentation during selection



commit 82e4f444c04ba90018d1813179f04ff6322df614
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sun Feb 14 16:29:49 2016 -0500

    Speak text indentation during selection

 src/orca/formatting.py       |    4 +-
 src/orca/script_utilities.py |   22 +++++++++++++++++++++
 src/orca/scripts/default.py  |    8 +++++-
 src/orca/speech_generator.py |   44 +++++------------------------------------
 4 files changed, 36 insertions(+), 42 deletions(-)
---
diff --git a/src/orca/formatting.py b/src/orca/formatting.py
index 8ff8da3..61ca27a 100644
--- a/src/orca/formatting.py
+++ b/src/orca/formatting.py
@@ -297,8 +297,8 @@ formatting = {
             'unfocused': '((substring and currentLineText) or labelAndName) + roleName'
             },
         pyatspi.ROLE_PARAGRAPH: {
-            'focused': 'labelOrName + readOnly + textRole + currentLineText + allTextSelection',
-            'unfocused': 'labelOrName + readOnly + textRole + currentLineText + allTextSelection + ' + 
MNEMONIC,
+            'focused': 'labelOrName + readOnly + textRole + textIndentation + currentLineText + 
allTextSelection',
+            'unfocused': 'labelOrName + readOnly + textRole + textIndentation + currentLineText + 
allTextSelection + ' + MNEMONIC,
             'basicWhereAmI': 'label + readOnly + textRole + textContent + anyTextSelection + ' + MNEMONIC,
             'detailedWhereAmI': 'label + readOnly + textRole + textContentWithAttributes + anyTextSelection 
+ ' + MNEMONIC
             },
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 42d2a2c..1ba63b2 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -2747,6 +2747,28 @@ class Utilities:
 
         return string
 
+    def indentationDescription(self, line):
+        if _settingsManager.getSetting('onlySpeakDisplayedText') \
+           or not _settingsManager.getSetting('enableSpeechIndentation'):
+            return ""
+
+        line = line.replace("\u00a0", " ")
+        end = re.search("[^ \t]", line)
+        if end:
+            line = line[:end.start()]
+
+        result = ""
+        spaces = [m.span() for m in re.finditer(" +", line)]
+        tabs = [m.span() for m in re.finditer("\t+", line)]
+        spans = sorted(spaces + tabs)
+        for (start, end) in spans:
+            if (start, end) in spaces:
+                result += "%s " % messages.spacesCount(end-start)
+            else:
+                result += "%s " % messages.tabsCount(end-start)
+
+        return result
+
     @staticmethod
     def absoluteMouseCoordinates():
         """Gets the absolute position of the mouse pointer."""
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index e96e56f..da7a5f8 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -3191,9 +3191,9 @@ class Script(script.Script):
 
         [line, caretOffset, startOffset] = self.getTextLineAtCaret(obj)
         if len(line) and line != "\n":
-            result = self.speechGenerator.generateTextIndentation(obj, line=line)
+            result = self.utilities.indentationDescription(line)
             if result:
-                self.speakMessage(result[0])
+                self.speakMessage(result)
 
             voice = self.speechGenerator.voice(string=line)
             line = self.utilities.adjustForLinks(obj, line, startOffset)
@@ -3222,6 +3222,10 @@ class Script(script.Script):
             return
 
         if len(phrase) > 1 or phrase.isalnum():
+            result = self.utilities.indentationDescription(phrase)
+            if result:
+                self.speakMessage(result)
+
             voice = self.speechGenerator.voice(string=phrase)
             phrase = self.utilities.adjustForRepeats(phrase)
             utterance = [phrase]
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index 5e5e630..699dee9 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -1253,53 +1253,21 @@ class SpeechGenerator(generator.Generator):
         result.extend(self._getACSS(obj, result[0]))
         return result
 
-    def generateTextIndentation(self, obj, **args):
-        return self._generateTextIndentation(obj, **args)
-
     def _generateTextIndentation(self, obj, **args):
         """Speaks a summary of the number of spaces and/or tabs at the
         beginning of the given line.
 
         Arguments:
         - obj: the text object.
-        - line: the string to check for spaces and tabs.
         """
-        if _settingsManager.getSetting('onlySpeakDisplayedText'):
-            return []
 
-        acss = self.voice(SYSTEM)
-        if not _settingsManager.getSetting('enableSpeechIndentation'):
+        line, caretOffset, startOffset = self._script.getTextLineAtCaret(obj)
+        description = self._script.utilities.indentationDescription(line)
+        if not description:
             return []
-        line =  args.get('alreadyFocused', "")
-        if not line:
-            [line, caretOffset, startOffset] = \
-              self._script.getTextLineAtCaret(obj)
-
-        # For the purpose of speaking the text indentation, replace
-        # occurances the non breaking space character with spaces.
-        line = line.replace("\u00a0", " ")
-        spaceCount = 0
-        tabCount = 0
-        utterance = ""
-        offset = 0
-        while True:
-            while (offset < len(line)) and line[offset] == ' ':
-                spaceCount += 1
-                offset += 1
-            if spaceCount:
-                utterance += "%s " % messages.spacesCount(spaceCount)
-            while (offset < len(line)) and line[offset] == '\t':
-                tabCount += 1
-                offset += 1
-            if tabCount:
-                utterance += "%s " % messages.tabsCount(tabCount)
-            if not (spaceCount  or tabCount):
-                break
-            spaceCount  = tabCount = 0
 
-        result = [utterance]
-        if result and result[0]:
-            result.extend(acss)
+        result = [description]
+        result.extend(self.voice(SYSTEM))
         return result
 
     #####################################################################


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