OSDN Git Service

CompoundTextInfo.collapse(): When end=True, don't assume that the end TextInfo is...
authorJames Teh <jamie@jantrid.net>
Tue, 21 Sep 2010 04:45:25 +0000 (14:45 +1000)
committerJames Teh <jamie@jantrid.net>
Tue, 21 Sep 2010 04:45:25 +0000 (14:45 +1000)
Fixes #910.

source/compoundDocuments.py

index 11d2439..551f9b5 100644 (file)
@@ -88,17 +88,24 @@ class CompoundTextInfo(textInfos.TextInfo):
 \r
        def collapse(self, end=False):\r
                if end:\r
-                       # The end of this object is equivalent to the start of the next.\r
-                       # As well as being silly, collapsing to the end of  this object causes say all to move the caret to the end of paragraphs.\r
-                       # Therefore, collapse to the start of the next instead.\r
-                       obj = self._endObj.flowsTo\r
-                       if obj:\r
-                               self._endObj = obj\r
-                               self._end = obj.makeTextInfo(textInfos.POSITION_FIRST)\r
+                       if self._end.compareEndPoints(self._endObj.makeTextInfo(textInfos.POSITION_ALL), "endToEnd") == 0:\r
+                               # The end TextInfo is at the end of its object.\r
+                               # The end of this object is equivalent to the start of the next.\r
+                               # As well as being silly, collapsing to the end of  this object causes say all to move the caret to the end of paragraphs.\r
+                               # Therefore, collapse to the start of the next instead.\r
+                               obj = self._endObj.flowsTo\r
+                               if obj:\r
+                                       self._endObj = obj\r
+                                       self._end = obj.makeTextInfo(textInfos.POSITION_FIRST)\r
+                               else:\r
+                                       # There are no more objects, so just collapse to the end of this object.\r
+                                       self._end.collapse(end=True)\r
                        else:\r
+                               # The end TextInfo is not at the end of its object, so just collapse to the end of the end TextInfo.\r
                                self._end.collapse(end=True)\r
                        self._start = self._end\r
                        self._startObj = self._endObj\r
+\r
                else:\r
                        self._start.collapse()\r
                        self._end = self._start\r