Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10344
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Apr 16, 2019 2:43 pm
I have a utility library stack always in use. One of the handlers resident there is:
Code: Select all
function makePlainText tText
repeat for each char tChar in tText
put numToChar(charToNum(tChar)) after temp
end repeat
return temp
end makePlainText
It is useful when I need to strip all styles and properties from whatever I have copied to the clipBoard. I invoke it with a keyboard shortcut.
That is not the point. Might it be fun and useful to have a new pane ("Interesting Handlers"?) to showcase small gadgetry like this, more accessible than the "Sample Stacks" arena.
Just a thought...
Craig
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10344
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Apr 16, 2019 2:56 pm
It just occurs to me, after reading the handler after decades of using it, that this:
Code: Select all
function makePlainText tText
repeat for each char tChar in tText
put tChar after temp
end repeat
return temp
end makePlainText
works just as well.
Oh well.
Craig
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Tue Apr 16, 2019 4:27 pm
Or, off the top of my head,
Code: Select all
set the clipboardData["styledText"] to empty
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10344
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Apr 16, 2019 5:13 pm
Jacque.
Adorable. It turns out that we do not even need that:
Code: Select all
set the clipBoardData to the clipBoardData
But my gadget, or its excesses, wasn't the point. A cute community handler pane...
Craig
-
Klaus
- Posts: 14206
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Tue Apr 16, 2019 5:27 pm
Question is:
What exactly are you passing to the function?
How do you pass STYLED text?

-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10344
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Wed Apr 17, 2019 2:16 am
Klaus.
Not sure what you mean. If I copy some styled text from a web page, and paste it into a text field somewhere, the styles and properties are preserved.
Oftentimes I only want the "raw" text. No colors, no changes in textSize or fonts. Apparently there are several ways (see posts above) to change the clipBoardData into raw text. That was only an example, though if it engenders a new thread, great.
Nobody wants to talk about a gadget pane. (Sob).
Craig
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10055
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Wed Apr 17, 2019 2:37 am
...should return only the plain text.
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10344
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Wed Apr 17, 2019 2:38 am
Ah,
A fourth way to do it.
Ah.
Sob...
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10055
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Wed Apr 17, 2019 3:52 am
With the first example, makePlainText, under what circumstances does the return value differ from the input?
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10344
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Wed Apr 17, 2019 4:39 am
Richard, and Klaus, I guess.
Any of the offerings, mine and others, will transform styled and property-laden text into "raw" text. The text I am speaking of is of the sort one gets when, say, one copies something from, say, a web page with lots of, er, styled text.
When one copies that text into, say, a LC field, all that style is preserved. Great.
I very often find transforming that styled text into simple raw text very useful.
Hey, I hate to change the subject, but I have an idea. Why don't we think about a new pane where cute, short utility gadgets can be posted? I bet that would be fun and instructive.
Sob...
Craig
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10055
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Wed Apr 17, 2019 4:47 am
dunbarx wrote: ↑Wed Apr 17, 2019 4:39 am
Richard, and Klaus, I guess.
Any of the offerings, mine and others, will transform styled and property-laden text into "raw" text. The text I am speaking of is of the sort one gets when, say, one copies something from, say, a web page with lots of, er, styled text.
When one copies that text into, say, a LC field, all that style is preserved. Great.
I very often find transforming that styled text into simple raw text very useful.
What is the format of the input string if not already text?
Styles require additional data. Usually this is done in binary form, such as within the inner operations of a field or the clipboard data. We can transform those into textual representations that include the formatting, such as htmlText or rtfText. But your script isn't working on binary structures nor parsing styled text representations, so I'm at a loss to conceive of an input that can be passed to it that isn't already plain text.
Hey, I hate to change the subject, but I have an idea. Why don't we think about a new pane where cute, short utility gadgets can be posted? I bet that would be fun and instructive.
Already built into the LC IDE: see Help -> Sample Stacks
Sob...
?
-
Klaus
- Posts: 14206
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Wed Apr 17, 2019 12:59 pm
FourthWorld wrote: ↑Wed Apr 17, 2019 4:47 am
What is the format of the input string if not already text?
Styles require additional data. Usually this is done in binary form, such as within the inner operations of a field or the clipboard data. We can transform those into textual representations that include the formatting, such as htmlText or rtfText. But your script isn't working on binary structures nor parsing styled text representations, so I'm at a loss to conceive of an input that can be passed to it that isn't already plain text.
That's why I asked!

-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10344
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Wed Apr 17, 2019 2:58 pm
I had early on mentioned the sample stacks. I was thinking more of sample handlers. I may start a new thread that has no examples. That has opened quite a discussion. I never meant it to.
Am I not making myself clear? If I copy a bit of text from a webpage, what lives in the clipBoard is likely very heavily styled and may contain properties (such as textSize) that may differ from one part of that text to another. If I then paste directly into a LC field, say, all that styling and all those properties are preserved.
Right?
Now then, oftentimes I want just the "raw" text. Not the styled text. The raw text. Not the styled text.
What am I missing? It must be something.
Craig
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Wed Apr 17, 2019 3:21 pm
I think the pane is a great idea, if I understand it right, something like the scripters handbook but in a more general way, i.e. everyone contributes, it isn't just your script gems.
Kind of like MetaCards examples reference, again, if I'm reading you rightly.

- Now I get it! (Maybe)
Not micro programs (like User Samples), but general handlers and the like.
-
richmond62
- Livecode Opensource Backer

- Posts: 10120
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Wed Apr 17, 2019 3:34 pm
Most Office suites (LibreOffice, Open Office, etc.) have a "paste Special" option where one can paste unformatted text.
This option is also available in the LiveCode Edit menu: command-control-V pastes plain text
Code: Select all
on mouseUp
put the text of fld "f1" into fld "f2"
end mouseUp
removes all styling.
Have a go with:
Code: Select all
on mouseUp
put the clipBoardData["text"] into fld "f1"
end mouseUp