\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