kryslt / KControls

Free components for Delphi and Lazarus, this is the main repository maintained by the original author.
BSD 3-Clause Clear License
58 stars 32 forks source link

KMemo paste plain text bug and patch #14

Closed kryslt closed 4 years ago

kryslt commented 4 years ago

kmemo_paste_text.zip Original report by David Bannon (Bitbucket: davidbannon, GitHub: davidbannon).


When pasting multiline plain text near the end of a kmemo, if the first line of (pasting)text is longer than remaining text in KMemo, the pasted content is split between the correct insertion point and the end of the content.

Reason is that TKMemoBlocks.InsertPlainText() calls InsertString() and then InsertParagraph() for each newline terminated string in the clipboard. But KMemoBlocks.InsertParagraph() relies on FSelectableLength to ensure its not at the end of content and FSelectableText is not updated after the InsertString() call. As a result, KMemo thinks the Index is beyond its own content length and puts the new Paragraph (and subsequent clipboard content) at end of its own content.

Solution is to call UpdateAttributes() after inserting the text, that updates FSelectableLength. Attached patch does this, run patch from the kcontrols/source directory.

Davo

kryslt commented 4 years ago

Fixed in 431a740fbd54a1728c74f5e8af1f43a9def71e56, patch applied.