Can't set the clipboard to plain text on Mac

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Can't set the clipboard to plain text on Mac

Post by japino » Tue Sep 05, 2017 11:26 am

I'm running into a weird issue which I swear worked properly in earlier versions of my app - which were built with earlier versions of LiveCode.

In my app I have a scrolling field with some text. The text doesn't have any formatting.
What I want to do is copy the text from that field to the clipboard for later pasting into another app.

My code is simply this:

Code: Select all

set the clipboardData["text"] to field "mail"
However, when look at the contents of the clipboard in the Finder, the Finder says that the contents of the clipboard is "RTFText".
When I paste contents into a text editor such as BBEdit, and then copy it to the clipboard again, the contents of the clipboard is "text", which is what I want.

The receiving app doesn't display the contents of the clipboard well when it is "RTFText". Everything is fine when the contents are "text".

I'm using LiveCode 8.1.6 on macOS Sierra 10.12.5.

What am I missing here?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can't set the clipboard to plain text on Mac

Post by dunbarx » Tue Sep 05, 2017 2:51 pm

Hard to say that there might not be invisible formatting attached to whatever text is in that field. Try this: (pseudo)

Code: Select all

get the text of the field
  repeat for each char tChar in it
      put numToChar(charToNum(tChar)) after temp
   end repeat
   see if temp fixes all that "RTFText" stuff
end makePlainText
In other words, compare the field text with a true plain-text copy. See if there is any difference. If there is, then there are things going on in the field text that you cannot see.

Craig Newman

japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Re: Can't set the clipboard to plain text on Mac

Post by japino » Tue Sep 05, 2017 3:50 pm

Thanks for your reply. Unfortunately, it doesn't solve the issue.

Code: Select all

on mouseUp
   put field "mail" into myText
   repeat for each char tChar in myText
      put numToChar(charToNum(tChar)) after temp
   end repeat
   set the clipboardData["text"] to temp  
end mouseUp
Running this code still give me type "RTF (Rich Text Format)" (to be precise) in Show Clipboard in the Finder.
Also happens with a brand-new stack with just 1 newly created field and 1 button.

I just verified that with an older version of my tool I did get "text" as the type of the clipboard data. I guess something changed in how the clipboard is handled between older versions of LiveCode and the current version. If nobody can tell me how to fix this, I'll try to restore an older version of LiveCode so that the correct functionality is back.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Can't set the clipboard to plain text on Mac

Post by Klaus » Tue Sep 05, 2017 4:43 pm

Just tested with LC 8.1.6 stable and LC 8.7.1 RC1 on macOS 10.12.6 and everything works as advertised!?

Code: Select all

on mouseUp
   set the clipboardData["text"] to field 1
   # field 1 contain BOLD and ITALIC styles
end mouseUp
No formatting in clipboard!

Code: Select all

on mouseUp
   put the clipboard
end mouseUp
-> text

Pasting into LC (and TextEdit etc...) results in non-formatted text!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Can't set the clipboard to plain text on Mac

Post by FourthWorld » Tue Sep 05, 2017 4:56 pm

RTF can be used to express plain (unstyled) text. I just tried your most recent example, along with the original form without the conversion to ASCII and back again:

Code: Select all

set the clipboardData["text"] to the text of fld "mail"
I have added some styling to the field text, yet both forms paste into a word processor (LibreOffice Write) without styling. If I use a simple copy command, the paste retains the styling.

Many changes have taken place with clipboard management since v7, and it's possible that LC now errs on the side of completeness when filling in the various elements of the data it hands off to the OS. It may be helpful to get some guidance from the engine team on this. I'll see if I can bring this thread to their attention to see if they feel it merits a bug report.

In the meantime, aside from the Finder showing the type as "RTF", are you seeing any issue with the text itself? Does it contain styles or other undesirable artifacts?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Can't set the clipboard to plain text on Mac

Post by bogs » Tue Sep 05, 2017 5:05 pm

LOL ! I was just conducting some experiments myself (although I use linux), and had pretty much come to the conclusions Richard and Klaus show.

Initially I set the textStyle of the field to plain, I got plain text.
Then I commented that out, and ran the code Craig gave you to try. Again I got plain text. Not sure whats going on anymore than that as I don't have a mac to test with, but Klaus apparently does :D

Image
Image

japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Re: Can't set the clipboard to plain text on Mac

Post by japino » Tue Sep 05, 2017 5:25 pm

Klaus wrote: Pasting into LC (and TextEdit etc...) results in non-formatted text!
In my stack and in my clipboard the text looks like plain text, but the type reported at the bottom of the clipboard window is RTF. Is it "text" for you, Klaus? When pasting into the receiving app I get plain text but the line spacing is too big.
When I paste into BBEdit and then copy again, the type reported is "text" and the text gets pasted into the receiving app with normal line spacing.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Can't set the clipboard to plain text on Mac

Post by FourthWorld » Tue Sep 05, 2017 5:43 pm

japino wrote:When pasting into the receiving app I get plain text but the line spacing is too big.
When I paste into BBEdit and then copy again, the type reported is "text" and the text gets pasted into the receiving app with normal line spacing.
Ah, now we're getting good actionable details. Thanks for that additional info.

I wrote a support rep on this, and was advised to consider three things:

1. Try LC v8.1.7
This new build was released just this morning, and includes a number of changes to clipboard management. It may or may not fix this one, but at least will provide good assessment of the current state of the engine.

2. Try the fullClipboardData instead of the clipboardData.
The former is a much newer structure and more complete than the older clipboardData. Indeed, there was much discussion about extending the older clipboardData, but backward compatibility made that problematic, so fullClipboardData was created as a more modern option which may be ideal for new code going forward.

3. File a bug report
Since the older clipboardData is maintained for backward compatibility, it should ideally retain its original functionality. There may be good reason for the change you're seeing, and once submitted to the QA system the team will have an opportunity to review it. Please include a sample stack that shows the issue, with a recipe for using it which will help them observe the result. But reports can be submitted to http://quality.livecode.com/
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Can't set the clipboard to plain text on Mac

Post by Klaus » Tue Sep 05, 2017 5:49 pm

Hi japino,
japino wrote:...In my stack and in my clipboard the text looks like plain text, but the type reported at the bottom of the clipboard window is RTF. Is it "text" for you, Klaus?
oh, sorry, did not pay attention to the bottom of the clipboard window. No, it reports "RTF"!
But pasting results in unformatted text.


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Can't set the clipboard to plain text on Mac

Post by FourthWorld » Tue Sep 05, 2017 7:10 pm

The line spacing aspect of this is curious. What do you get when you query the clipboardData["htmlText"]? Can you post that here?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Re: Can't set the clipboard to plain text on Mac

Post by japino » Wed Sep 06, 2017 8:35 am

FourthWorld wrote:The line spacing aspect of this is curious. What do you get when you query the clipboardData["htmlText"]? Can you post that here?
I get the text that's inside the field with all Return characters replaced by a space. The Clipboard window in the Finder still displays the type of the clipboard as RTF.

japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Re: Can't set the clipboard to plain text on Mac

Post by japino » Wed Sep 06, 2017 8:44 am

FourthWorld wrote: 1. Try LC v8.1.7
2. Try the fullClipboardData instead of the clipboardData.
3. File a bug report
I tried LC v8.1.7 with the same result: the type reported in the Clipboard window in the Finder is RTF, where it should be "text", as before.
I tried fullClipboardData, but the result is exactly the same.
I will file a bug report.

Thanks all!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Can't set the clipboard to plain text on Mac

Post by FourthWorld » Wed Sep 06, 2017 3:31 pm

japino wrote:
FourthWorld wrote:The line spacing aspect of this is curious. What do you get when you query the clipboardData["htmlText"]? Can you post that here?
I get the text that's inside the field with all Return characters replaced by a space.
That would be a very rare bug. As the element name implies, the clipboardData["htmlText"] should return an HTML-like representation of the text. At a minimum you should see the text wrapped between "<p>" and "</p>". If you see no HTML-like tags either something is wrong with the syntax when you tried it or there's something very strange that I've never seen before about how the engine is handling the request.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Re: Can't set the clipboard to plain text on Mac

Post by japino » Wed Sep 06, 2017 4:18 pm

Just tried again with "htmlText" in a fresh stack. Result has no tags and the Return characters are gone. The code is simply this:

Code: Select all

on mouseUp
   set the clipboardData["htmlText"] to  field "myField"
end mouseUp
The bug I logged about not getting plain text but RTF text has been acknowledged. It's a known issue in version 8 and it was OK in version 7.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Can't set the clipboard to plain text on Mac

Post by FourthWorld » Wed Sep 06, 2017 4:23 pm

Thanks for filing the bug report. What's the report number/URL so we can follow its progress?

As for the seeming htmlText bug, the code is less important than the output. If you can post the output from that array query it may help us understand either why the HTML-like tags aren't present, or if they are why it seems to include line spacing info.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”