OSDN Git Service

Fix for #948 (bug where not all text was copied to the clipboard when copying from...
authorMichael Curran <mick@kulgan.net>
Wed, 29 Sep 2010 23:57:31 +0000 (09:57 +1000)
committerMichael Curran <mick@kulgan.net>
Wed, 29 Sep 2010 23:57:31 +0000 (09:57 +1000)
*Implement a new clipboardText property on the base TextInfo class, which returns the text property, processed by convertCrlf.
*TextInfo.copyToClipboard: pass the clipboardText property to api.copyToClip rather than convertCrlf(self.text).
*Base virtualBuffer: rather than implementing a copyToClipboard method, instead implement a clipboardText property. It still inserts linefeeds in between block fields etc, but just returns the text, rather than copying it to the clipboard now of course.
*DisplayModelTextInfo: implement a clipboardText property, which fetches its super clipboardText property, but converts NULLs to spaces before returning.

source/displayModel.py
source/textInfos/__init__.py
source/virtualBuffers/__init__.py

index fc0b3f9..184d241 100644 (file)
@@ -92,6 +92,8 @@ class DisplayModelTextInfo(OffsetsTextInfo):
                offset=self._getClosestOffsetFromPoint(x,y)\r
                return offset,offset\r
 \r
+       def _get_clipboardText(self):\r
+               return super(DisplayModelTextInfo,self).clipboardText.replace('\0',' ')\r
 \r
 class EditableTextDisplayModelTextInfo(DisplayModelTextInfo):\r
 \r
index ff8dcfd..87f96fa 100755 (executable)
@@ -315,13 +315,17 @@ class TextInfo(baseObject.AutoPropertyObject):
                """Retrieves x and y coordinates corresponding with the textInfo start. It should return Point"""\r
                raise NotImplementedError\r
 \r
+       def _get_clipboardText(self):\r
+               """Text suitably formatted for copying to the clipboard. E.g. crlf characters inserted between lines."""\r
+               return convertToCrlf(self.text)\r
+\r
        def copyToClipboard(self):\r
                """Copy the content of this instance to the clipboard.\r
                @return: C{True} if successful, C{False} otherwise.\r
                @rtype: bool\r
                """\r
                import api\r
-               return api.copyToClip(convertToCrlf(self.text))\r
+               return api.copyToClip(self.clipboardText)\r
 \r
        def getTextInChunks(self, unit):\r
                """Retrieve the text of this instance in chunks of a given unit.\r
index 3dc28aa..d04a00b 100644 (file)
@@ -189,11 +189,11 @@ class VirtualBufferTextInfo(textInfos.offsets.OffsetsTextInfo):
                        return startOffset.value,endOffset.value\r
                return super(VirtualBufferTextInfo, self)._getUnitOffsets(unit, offset)\r
 \r
-       def copyToClipboard(self):\r
+       def _get_clipboardText(self):\r
                # Blocks should start on a new line, but they don't necessarily have an end of line indicator.\r
                # Therefore, get the text in block (paragraph) chunks and join the chunks with \r\n.\r
                blocks = (block.strip("\r\n") for block in self.getTextInChunks(textInfos.UNIT_PARAGRAPH))\r
-               return api.copyToClip("\r\n".join(blocks))\r
+               return "\r\n".join(blocks)\r
 \r
        def getControlFieldSpeech(self, attrs, ancestorAttrs, fieldType, formatConfig=None, extraDetail=False, reason=None):\r
                textList = []\r