Ticket #149: paragraphOffsets.py

File paragraphOffsets.py, 1.7 KB (added by pvagner, 4 years ago)

Implementation of the _getParagraphOffsets() method for the NVDA textInfo class. This assumes blank lines are splitting the text into paragrapsh and paragraph can't start with space or a punctuation symbols. For testing purposes you can add it to any of these classes as long as you can test it.

Line 
1        def _getParagraphOffsets(self,offset):
2                (lineStart,lineEnd)=self._getLineOffsets(offset)
3                start=lineStart
4                while lineStart>0 and self._getTextRange(lineStart,lineEnd).isspace():
5                        (lineStart,lineEnd)=self._getLineOffsets(lineStart-1)
6                start=lineStart
7                if lineStart>=0 and self._getTextRange(lineStart,lineEnd)[0:1].isalnum():
8                        (prevLineStart,prevLineEnd)=self._getLineOffsets(lineStart-1)
9                        while prevLineStart>0 and self._getTextRange(lineStart,lineEnd)[0:1].isalnum():
10                                lineStart=prevLineStart
11                                lineEnd=prevLineEnd
12                                (prevLineStart,prevLineEnd)=self._getLineOffsets(lineStart-1)
13                        start=lineStart
14                        if prevLineStart==0:
15                                if self._getTextRange(lineStart,lineEnd).isspace():
16                                        start=prevLineStart
17                                elif not self._getTextRange(lineStart,lineEnd)[0:1].isalnum():
18                                        start=lineStart
19                                else:
20                                        start=prevLineStart
21                (lineStart,lineEnd)=self._getLineOffsets(offset)
22                end=lineEnd
23                if lineEnd<self._getStoryLength()-1:
24                        (nextLineStart,nextLineEnd)=self._getLineOffsets(lineEnd+1)
25                        while nextLineEnd<=self._getStoryLength()-1 and self._getTextRange(nextLineStart,nextLineEnd)[0:1].isalnum() and not self._getTextRange(lineStart,lineEnd).isspace():
26                                lineStart=nextLineStart
27                                lineEnd=nextLineEnd
28                                (nextLineStart,nextLineEnd)=self._getLineOffsets(lineEnd+1)
29                        while nextLineEnd<self._getStoryLength()-1 and self._getTextRange(nextLineStart,nextLineEnd).isspace():
30                                lineStart=nextLineStart
31                                lineEnd=nextLineEnd
32                                (nextLineStart,nextLineEnd)=self._getLineOffsets(nextLineEnd+1)
33                        if self._getTextRange(nextLineStart,nextLineEnd).isspace():
34                                end=nextLineEnd
35                        else:
36                                end=lineEnd
37                return (start,end)
38