Keep formatting when moving text

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
david_fff
Posts: 29
Joined: Wed Nov 12, 2014 5:29 pm

Keep formatting when moving text

Post by david_fff » Wed Nov 12, 2014 5:34 pm

How can I keep the formatting of text (i.e., super and subscripts) when using "Put" to move text from one text field to another?
Thanks, David

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

Re: Keep formatting when moving text

Post by Klaus » Wed Nov 12, 2014 5:50 pm

Hi David,

you can't! PUT will only put "naked" ASCII text into a field. 8)

But you can use the htmltext (and maybe the RTFTEXT prop, but never used that one) property to preserve formatting, something like:
...
set the htmltext of fld "the formerly empty field" to the htmltext of fld "the formatted one"
...


Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3361
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Keep formatting when moving text

Post by bn » Wed Nov 12, 2014 6:09 pm

Hi David,

welcome to the forum.

If you say "put the text of field "f1" into field "f2", or "put field "f1" into field "f2" which is the same, you just take the text without formatting, as you have found out.

There is the htmlText of field "f1" that contains the formatting information.

Code: Select all

set the htmlText of field "f2" to the htmlText of field "f1"
will do the trick.

you can get the htmlText of chunks too and say

Code: Select all

set the htmlText of char 1 to 10 of field "f2" to the htmlText of word 10 to 35 of field "f1"
the styledText of a field is also a property of the field that contains formatting information

so

Code: Select all

set the styledText of field "f2" to the styledText of field "f1"
would give you the same result as "htmlText"

Since htmlText, styledText, unicodeText, formattedText are properties of a field you have to use the

"set the [your property here] instead of put.

Oh, if your want to have a look at the htmlText of a field you can say

Code: Select all

put the htmlText of field "f1" into field "f2"
here you have the actual html in field 2, not the formatted text of field "f1"


Kind regards
Bernd

Edit: I just see that Klaus was faster.

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

Re: Keep formatting when moving text

Post by dunbarx » Wed Nov 12, 2014 8:36 pm

&*^%$^#^*

Klaus is ALWAYS faster.

Grumble...

david_fff
Posts: 29
Joined: Wed Nov 12, 2014 5:29 pm

Re: Keep formatting when moving text

Post by david_fff » Thu Nov 13, 2014 4:48 am

Thank you for the response, but there is this issue: I am adding the formatted text with super/subscripts to a field which already has text in it. (What I am really doing is creating a test from selected question cards.) The set command replaces any text in the destination field with the text in the source field. What you wrote about "put the htmlText..." looks promising though, if I could flip the htmltext (after I put it after last line of the destination fld) back to showing sub or superscripts. It could all be done transparently, much like how a browser transparently converts htmlText to formatted text (bold, italics, super/sub, etc.). This is undoubtedly an amateur-hour solution to an easy question but I am grateful for any help.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3361
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Keep formatting when moving text

Post by bn » Thu Nov 13, 2014 9:20 am

Hi David,

if you want to append the formattedText of field "f1" (source) to field "f2" (destination) at the end of field "f2" in a new line you could do this

Code: Select all

on mouseUp
   set the htmlText of field "f2" to the htmlText of field "f2" & return & the htmlText of field "f1"
end mouseUp
Kind regards
Bernd

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

Re: Keep formatting when moving text

Post by dunbarx » Thu Nov 13, 2014 3:29 pm

Hi.

What Bernd said.

Know that when you are able to manipulate chunks of text, you are able to use such keywords as "after", "before" and "into":

put yourText after fld 2 --works
but
put yourHTMLText after fld 2. --This syntax does not hunt.

Because the HTMLText is a property, not a chunk, and therefore must be handled differently. You can only "set" and "get" properties. You cannot "put" them or, say, "delete" them. So what Bernd told you to do was to extract those properties and then re-assemble them (pseudoCode):

set the property of mainThing to (the property of mainThing) & return & (the property of secondaryThing)

The (new) property of mainThing is thus assembled from two other properties, concatenated with a return in this example.

Craig Newman

david_fff
Posts: 29
Joined: Wed Nov 12, 2014 5:29 pm

Re: Keep formatting when moving text

Post by david_fff » Thu Nov 13, 2014 11:42 pm

Thank you both so much! This really helps.

Post Reply

Return to “Talking LiveCode”