Page 1 of 1
Store formatted text in to variables
Posted: Sat Apr 15, 2017 3:58 pm
by dayakar
Hi
Is it possible to put the formatted text of a field into a variable and then put the variable content into another field with the same formatting?
Please take a look at the following screenshot 1. In field 1, the backgroundcolor of word 2 is yellow and planning to put this word 2 along with the formatting into a variable and put the variable into field 2 with same formatting like in the field 1 as shown in screenshot 2.
Thanking you in advance.
Screenshot 1
Screenshot 2
Regards
Dayakar
Re: Store formatted text in to variables
Posted: Sat Apr 15, 2017 4:36 pm
by richmond62
Err . . . I cheated
You can make things even shorter by changing the script to this:
Re: Store formatted text in to variables
Posted: Sat Apr 15, 2017 5:08 pm
by dayakar
Thank you very much Richmond for your alternative solution. The stack is helpful to know about clickText and the logic applied.
But good to know if there is an option to store the formatting info in the variable.
Re: Store formatted text in to variables
Posted: Sat Apr 15, 2017 5:34 pm
by richmond62
an option to store the formatting info in the variable
A
variable can only store
one value; and that would have to be either
your
string (the word) or the RGB code for the
backGroundColor, it could not be both.
Re: Store formatted text in to variables
Posted: Sat Apr 15, 2017 5:56 pm
by dayakar
Thanks for the response.
Is there any option in LiveCode to find the position of the word pasted using a variable in field? So, that position could be passed into another variable and set the color of the pasted text by referring to word Position as shown in the following code (it is not working but just to give an idea).
Code: Select all
put the position of CT in fld "f2" into CTPosition
set the backGroundColor of word CTPosition of fld "f2" to KOLOR
Re: Store formatted text in to variables
Posted: Sat Apr 15, 2017 5:56 pm
by Klaus
HI dayakar,
to preserve formatting use "the htmltext of..." or "the rtftext of...".
Like this in your example:
...
set the htmltext of fld 1 to the htmltext of word 2 of fld 1
...
Best
Klaus
Re: Store formatted text in to variables
Posted: Sat Apr 15, 2017 9:07 pm
by richmond62
It would be interesting @Klaus to know why LiveCode seems unable to set Italic text on Mac OS (no problem on Linux: dunno anent Windows).
Re: Store formatted text in to variables
Posted: Sun Apr 16, 2017 9:08 am
by Klaus
No idea, works here in LC 9 dp6!
I used the LC "Text" menu for formatting.
Re: Store formatted text in to variables
Posted: Sun Apr 16, 2017 2:38 pm
by dayakar
Thanks @Klaus it's working fine with htmlText.
Re: Store formatted text in to variables
Posted: Sun Apr 16, 2017 3:06 pm
by dunbarx
Richmond.
I am still in v.6.7. I never noticed it before, but italic does not display correctly. The property sticks, just not the actual text. If it works in v9 as per Klaus, it might be interesting to see in which version it actually appeared, and if it was ever noted as such.
Craig
Re: Store formatted text in to variables
Posted: Sun Apr 16, 2017 3:34 pm
by Klaus
Just tested with LC 8.1.4 RC1, same result as in the screenshot above, in other words it works as exspected!