TextArea losing LineSpacing with Copy&Paste

Hello,

In my project, one can do the following steps, which I’m unsure it is the expected behaviour.
•In a multiline TextArea, change the LineSpacing (say, to 2);
•Type some text, preferably having several lines;
•Select all and copy;
•Close the window and restart (either recompile the app or re-open another instance of the window), making sure the TextArea keep its default LineSpacing of 1 (e.g. this would be the next time the user uses the application);
•Paste.

The pasted text appears much like it was when it was copied, minus the LineSpacing difference.
Now, open TextEdit and paste the same text: the LineSpacing is set accordingly.

I understand there may be cases where one behaviour (or the other) may be wanted, although I guess the way TextEdit works is probably “more often expected”.

One could store the LineSpacing of the source TextArea in the clipboard, using RawData, but if the user pastes in TextEdit and copy from there, this RawData gets lost anyway.

Strangely, I couldn’t find a related question in Feedback, in this forum or elsewhere on the Internet (searching for Xojo only).

What’s the “expected” behaviour and why?

I think the copy-and-paste buffer of an operating system will store limited formatting information when it comes to textual data.

For example, if you copy some formatted text from a webpage, then paste it into MS Word. Word has some built-in capabilities to understand the additional formatting information (in this case HTML) and Word will typically display the formatting similar to how it was in the webpage (but not always, like when pasting an HTML table)

But if you pasted that same HTML formatted text into a simple text editor, like Notepad or a Xojo code window, the copy buffer will automatically remove the formatting information during the paste action and just supply the raw text, because the source and target applications and/or controls don’t have compatible formatting capabilities.

With that said, TextEdit on Mac does understand and accept HTML as well as RTF information. But it could be that the line-spacing part of the formatting is more a characteristic of the control rather than the formatting information of the text. So more than likely the line spacing parts are not compatible or maybe not included in the pasted information at all.

In other words, there will be limits to what copy-and-paste formatting information of text is compatible between applications and controls. I don’t see this necessarily as a Xojo limitation, but rather a compatibility issue between applications. Copy and pasting is just the easiest way to highlight those incompatibilities.

Another example is if you copy the syntax coloured text from a Xojo code window and paste it into TextEdit, the colours are not copied.

Note: the above is just my assumption based on experience.

I hope that helps.

I don’t think TextArea fully manages line spacing, like a word processing would do it.

There is actually no property allowing it.

Please notice that on MacOS the line spacing is part of the paragraph style (NSParagraphStyleMBS class in our plugins)

I am not sure whether Textarea control handles that for the clipboard.
But you can try NSTextViewMBS class and call Copy method there.

Or you get selected styled text from NSTextViewMBS (using selectedRange), put it with right NSParagraphStyleMBS object into a NSMutableAttributedStringMBS and put this yourself into the clipboard (NSPasteboardMBS class).
Or use CopyToClipboard method we added to NSAttributedStringMBS class.

Please, study the Clipboard contents, then you will start to understand the mechanism involved in Copy/Cut and Paste.

In macOS, copy some Firefox styled text in the clipboard and check in AppleScript Editor what is in the Clipboard: you will be surprised.

As we all know, each application takes its own from what is stored in the Clipboard.

clipboard info # in the Script Editor (macOS) will return:

{{«class utf8», 186}, {«class ut16», 374}, {string, 186}, {Unicode text, 372}}

At Paste time the application where you Paste the data will take utf8, utf16 or Unicode text, thus the differences you can see depending on the application…

This is the same that happens with images (with jpg, png, tiff, etc.)

As developer we know far more than the average user who always ask why (s)he cannot paste the Clipboard contents in application <my_application>… :wink: