Text format

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

Post Reply
Rod Edwardson
Posts: 23
Joined: Sun Mar 03, 2013 1:09 am

Text format

Post by Rod Edwardson » Wed Apr 10, 2013 4:21 pm

Hello

I have an issue that has me stumped. I have a button that clears some text formatting in a text field. For some reason the result provides me with underlines text in the first (Field s) text field. I have tried setting the the textstyle to plain with still no result. Any ideas?

Code: Select all

on mouseUp
   if the environment = "development" then touchEnd 1
      select the text of field "Field s" 
   set the textColor of the selectedText to black
   set the backgroundcolor of selectedText to white
   put "" into Field "fldNotes"
   select the text of field "fldHidden"
  end mouseUp

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Text format

Post by jmburnod » Wed Apr 10, 2013 5:32 pm

Hi Rod,
I tried your script directly and i was surprised it work without error
(except the second line of course).
About your script:
textColor and backgroundcolor are only for controls not for selectedText
It works not how expected but with a strange behavior. Congratulation you created something new. :D

I put a little stack in attachment like you described
1. A blue "points underline" as you said on the selected text for the first
2. An expected behavior for the second
I have no explanation. Does anyone have one ?
Best regards
Jean-Marc
Attachments
StrangeSelectText.livecode.zip
(10.09 KiB) Downloaded 272 times
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Text format

Post by jacque » Wed Apr 10, 2013 5:35 pm

Your script should work if you use "the selectedchunk" instead of "the selectedtext".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Text format

Post by jmburnod » Wed Apr 10, 2013 5:47 pm

Rod,
Sorry, I'm wrong
textColor and backgroundcolor are only for controls not for selectedText
selectedChunk is probably what you want but i don't understand the goal

Jacque,
I never seen this fld behavior

Best regards
Jean-Marc
https://alternatic.ch

Rod Edwardson
Posts: 23
Joined: Sun Mar 03, 2013 1:09 am

Re: Text format

Post by Rod Edwardson » Wed Apr 10, 2013 11:50 pm

Hello

selectedChunk does not seem to work either. To confuse things further, I have another stack that uses the same script and it works fine. Anyway, not the best way to handle it I'm sure but I have come up with a fix for my goal. I have a string of text that is stored in a variable. When my stack loads, that text gets placed into the text box. I have an option menu that searches the text box for different words and formats the result with different colour text. In the clear formatting button, where the script in question resides, I have amended it just closed the stack and re-opened it again. When it re-opens, the initial text from the variable gets put back into the field, nicely formatted as I want it. Works but not ideal. And I am not sure why its working on the other stack? Oh well, thanks to all for their ideas!

Rod

asayd
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Mon Apr 10, 2006 7:02 pm
Contact:

Re: Text format

Post by asayd » Thu Apr 11, 2013 12:26 am

Rod,
I'm not exactly sure what you are trying to do, but if you just want to clear all formatting from the text in the field try something like this:

Code: Select all

set the textStyle of char 1 to -1 of field "myFld" to empty
If you just set the textStyle of the field, the properties that have been previously set on any chunk of text in the field will retain those properties. Think of text inside a field as a child of the field that can have its own properties.

Hope this helps.
Devin
Devin Asay
Learn to code with LiveCode University
https://livecode.com/store/education/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Text format

Post by dunbarx » Thu Apr 11, 2013 1:27 am

What Asayd said.

And his description of the situation is spot-on. I frequently trip up on this, carelessly setting field style properties where the field already contains styled text within it, and expecting the text itself to follow suit.

Craig Newman

Post Reply