styledtext, mixed content and clipboarddata
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
styledtext, mixed content and clipboarddata
Ran across something curious today:
If I have a field containing a hyperlink, and script with:
set the clipboarddata["styledtext"] to the styledText of me
.. then when user pastes clipboard in another app (e.g. Slack) they get a hyperlink.
But, if I have a mix of a link and some unstyled text, and I do the same thing, then when user pastes, they just get unstyled text, it looses the link.
Anyone have any idea why?
Rod
If I have a field containing a hyperlink, and script with:
set the clipboarddata["styledtext"] to the styledText of me
.. then when user pastes clipboard in another app (e.g. Slack) they get a hyperlink.
But, if I have a mix of a link and some unstyled text, and I do the same thing, then when user pastes, they just get unstyled text, it looses the link.
Anyone have any idea why?
Rod
Last edited by rodneyt on Sat Sep 03, 2022 3:55 am, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: styledtext, mixed content and clipboarddata
What app are they pasting into, on which OS?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: styledtext, mixed content and clipboarddata
I know a lot of programs parse what either is or looks like a valid link into an actual link. That must be what is happening here.
But you have issues. First, you have a left bracket "[" mixed with a right parenthesis ")". This will not compile. Is it a typo in the post? You cannot compile with two actual parentheses. And if you apply both brackets, LC compiles, but throws an error.
So I do not know what your handler is doing at all.
Is it that you do NOT want the hyperlink, only the copied string?.
Please write back...
Craig
But you have issues. First, you have a left bracket "[" mixed with a right parenthesis ")". This will not compile. Is it a typo in the post? You cannot compile with two actual parentheses. And if you apply both brackets, LC compiles, but throws an error.
So I do not know what your handler is doing at all.
Is it that you do NOT want the hyperlink, only the copied string?.
Please write back...
Craig
Re: styledtext, mixed content and clipboarddata
I rarely use the clipboard for anything but text and objects, so I invariably use the "clipBoardData". This can be something like:
So were you trying to extract the style of a chunk of text in a field that has mixed styles? Or to get the style of the field itself or the owner of that field?
Did I mention you need to write back?
Craig
Code: Select all
on mouseUp
set the clipboarddata["text"] to word 2 of fld 1
-or even
set the clipboarddata to word 2 of fld 1
end mouseUp
Did I mention you need to write back?
Craig
Re: styledtext, mixed content and clipboarddata
Thanks Craig. Re writing back - I'm in NZ so it may be up to a day before I respond, but I read everything.dunbarx wrote: ↑Fri Sep 02, 2022 11:14 pmI know a lot of programs parse what either is or looks like a valid link into an actual link. That must be what is happening here.
But you have issues. First, you have a left bracket "[" mixed with a right parenthesis ")". This will not compile. Is it a typo in the post? You cannot compile with two actual parentheses. And if you apply both brackets, LC compiles, but throws an error.
So I do not know what your handler is doing at all.
Is it that you do NOT want the hyperlink, only the copied string?.
Please write back...
Craig
I was typing the code snippet directly rather than copy/paste - bracket was a typo (fixed).
I think you are right, other apps are probably parsing plaintext into a valid link, rather than understanding styled text on clipboard.
I guess my question is why if you copy styled text from (say) email to (say) Slack application (or other app) when pasting the styled text is fully restored. I.e. styled text on clipboard is understood as Styled Text. Whereas "styled text" on Livecode clipboard is (usually) interpreted as plain text when pasted to another app. I haven't explored/researched/tested this issue in depth, just an observation... wondering if others have observed this and done any sleuthing...
Rod
Re: styledtext, mixed content and clipboarddata
Hi Rod, not sure what you mean 'the user gets a link' in external software - do you mean it's styled like a link? (by link i presume you mean URL which is just plain text - and software that can display a URL will usually be able to format it as such internally - maybe the ["styledText"] interferes with this?).rodneyt wrote: ↑Fri Sep 02, 2022 8:13 amIf I have a field containing a hyperlink, and script with:
set the clipboarddata["styledtext"] to the styledText of me
.. then when user pastes clipboard in another app (e.g. Slack) they get a hyperlink.
But, if I have a mix of a link and some unstyled text, and I do the same thing, then when user pastes, they just get unstyled text, it looses the link.
have you tried using clipboardData["text"] instead of ["styledText"]?
On this note I found that both ["styledText"] and ["htmlText"] fail to copy/paste correctly - all different stylings are converted to a single style, eg if you have a mix of bold, italic and underlined text, all the 'styled' text becomes italic when pasted (unstyled text is unaffected), both when copy/pasting to another field in LC or in a word processor. If you throw in some text at the start of the line and specifically format that text as a 'link' in LC, then all styled text becomes underlined when pasted!
The only thing that seems to work exactly as advertised is ["RTF"] so if you're trying to paste a URL styled like a link and the target software understands RTF maybe try this instead?
But chances are that if you just copy/paste plain text, the target software would format it itself...
Alternatively you could maybe paste html if the external software manages this? (here again clipboardData["html"] fails, but i guess you could set the text of another field to the htmlText of the source field and then copy that as text instead, or some such.
S.
Re: styledtext, mixed content and clipboarddata
At first I thought that all would be solved by (pseudo):
This can be deconstructed perfectly in LC:
It works fine but can hardly be pasted anywhere directly, including back into LC itself. You get the htmlText instead of the styled text.
Craig
Code: Select all
set the clipboardData to the htmlText of yourChunk
Code: Select all
set the htmlText of fld 2 to the htmlText of fld 1
Craig
Re: styledtext, mixed content and clipboarddata
Stam.
If I copy the text from a field that contains a link, that link comes over styled as bold when pasted into in a couple of other programs I tried.
Craig
If I copy the text from a field that contains a link, that link comes over styled as bold when pasted into in a couple of other programs I tried.
Craig
Re: styledtext, mixed content and clipboarddata
Hi Craig,
My point was that set the clipboardData["htmlText"] or ["styledText"] doesn't seem to work.
I had never needed to use this previously but tested it now and found that the only thing that does seem to paste the text as formatted is clipboardData["RTF"]. But this doesn't now seem to preserve 'link' style. All other styles are preserved.
Stam
My point was that set the clipboardData["htmlText"] or ["styledText"] doesn't seem to work.
I had never needed to use this previously but tested it now and found that the only thing that does seem to paste the text as formatted is clipboardData["RTF"]. But this doesn't now seem to preserve 'link' style. All other styles are preserved.
Stam
Re: styledtext, mixed content and clipboarddata
To be more precise:
[styledText] does work there is only 1 style .
If the text is specifically formatted as plain and you add text that is specifically formatted as 'link', then this works and pasted the text with the link formatted as 'link', as below:
But if you mix/match styles it doesn't. If there is text formatted as 'link' then any other text that has any random style is pasted as style 'link' The same applies to [htmlText] - [RTF] works as expected but clearly doesn't know how to style 'links' so these are pasted as plain text.
Testing this further, there seems to be a hierarchy of which style dominates if you mix and match styles and try to paste the styled text with ["styledText"] or ["htmlText"]. Only 1 dominant style is set when pasting the text - the hierarchy seems to be link > underline > italic > bold.
if any of the text is formatted as 'link' then any other formatted text is styled as 'link' on paste, regardless of source style as shown above.
If there is no link, if there is any text styled as 'underlined' then any other formatted text is styled as 'underlined' on paste, regardless of source.
The same applies to 'italic' - ie if source contains bold and italic, pasting it will change the text with style attributes all to italic.
So to answer the OP's question, if the non-link text is specifically assigned a 'plain' text style, this should work.
[styledText] does work there is only 1 style .
If the text is specifically formatted as plain and you add text that is specifically formatted as 'link', then this works and pasted the text with the link formatted as 'link', as below:
But if you mix/match styles it doesn't. If there is text formatted as 'link' then any other text that has any random style is pasted as style 'link' The same applies to [htmlText] - [RTF] works as expected but clearly doesn't know how to style 'links' so these are pasted as plain text.
Testing this further, there seems to be a hierarchy of which style dominates if you mix and match styles and try to paste the styled text with ["styledText"] or ["htmlText"]. Only 1 dominant style is set when pasting the text - the hierarchy seems to be link > underline > italic > bold.
if any of the text is formatted as 'link' then any other formatted text is styled as 'link' on paste, regardless of source style as shown above.
If there is no link, if there is any text styled as 'underlined' then any other formatted text is styled as 'underlined' on paste, regardless of source.
The same applies to 'italic' - ie if source contains bold and italic, pasting it will change the text with style attributes all to italic.
So to answer the OP's question, if the non-link text is specifically assigned a 'plain' text style, this should work.
Last edited by stam on Sun Sep 04, 2022 4:02 am, edited 1 time in total.
Re: styledtext, mixed content and clipboarddata
test stack attached
----------
EDIT: I submitted a bug report for this here: https://quality.livecode.com/show_bug.cgi?id=23922
----------
EDIT: I submitted a bug report for this here: https://quality.livecode.com/show_bug.cgi?id=23922
- Attachments
-
- styledTextCopyIssue.livecode.zip
- (1.93 KiB) Downloaded 155 times
-
- VIP Livecode Opensource Backer
- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: styledtext, mixed content and clipboarddata
Sounds like a bug I'll bet the team would like to fix.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: styledtext, mixed content and clipboarddata
I wonder WHY this does NOT work?
Code: Select all
on mouseUp
put 1 into DUMA
repeat until word DUMA of fld "fTEXT" is empty
set the styledText of fld "fTEXT2" to ((the styledText of fld "fTEXT2") && the styledText of word DUMA of fld "fTEXT")
add 1 to DUMA
end repeat
end mouseUp
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: styledtext, mixed content and clipboarddata
Um . . . ?
- -
WORKS! partially
What I DO notice is that ALL styledText after a Hyperlink gets styled as a Hyperlink as well, but
styledText before a Hyperlink gets set to the style it should be.
So, at the risk of stating the obvious . . .
There needs to be some way of extracting any Hyperlinks from the source text and then reinserting them later.
MacOS 13 beta whatever
LC 9.6.1. Community
- -
WORKS! partially

What I DO notice is that ALL styledText after a Hyperlink gets styled as a Hyperlink as well, but
styledText before a Hyperlink gets set to the style it should be.
So, at the risk of stating the obvious . . .
There needs to be some way of extracting any Hyperlinks from the source text and then reinserting them later.
MacOS 13 beta whatever
LC 9.6.1. Community
- Attachments
-
- Stylish.livecode.zip
- Stack.
- (1.13 KiB) Downloaded 136 times
Last edited by richmond62 on Sun Sep 04, 2022 9:59 am, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: styledtext, mixed content and clipboarddata
My experience in that direction suggests that all bets are off.Sounds like a bug I'll bet the team would like to fix.
AND, it seems that there might be no bug at all.
