Detecting change to FormattedText

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 452
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Detecting change to FormattedText

Post by kaveh1000 » Sun Oct 18, 2020 9:04 am

Hi folks

I have a field with a large volume of text. I am doing some moving around for which I need the current value of FormattedText, as I need to know where the soft line breaks are, and the number of lines after line breaking.

If the text itself changes, I can use

Code: Select all

on TextChanged
   (update value of FormattedText)
end TextChanged
but the FormattedText can also change of the following are modified:

text size
field dimensions
field border
etc


I want to minimise the call to grab the FormattedText, so looking for something like

Code: Select all

on FormattedTextChanged
   (update value of FormattedText)
end FormattedTextChanged
Any ideas on the best way to achieve this?
Kaveh

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8143
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Detecting change to FormattedText

Post by FourthWorld » Sun Oct 18, 2020 9:29 am

You'll need to update the routine that responds to formattedText changes in the UI you provide for altering the properties that will affect it.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 452
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Detecting change to FormattedText

Post by kaveh1000 » Sun Oct 18, 2020 9:42 am

Not sure I understand Richard. Let me describe the use case:

The user will be interacting with the field (with locked text) using the mouse and/or arrow keys. I need to know which line they clicked on, counting from the top in FormattedText, as well as the length of the lines. There is a lot of interaction, but the field content and size only changes occasionally.

I could check the formattedText at each mouse click and arrow key, but that is too much drain on the system. So I want to read the value of FormattedText only when the text is updated, or when the field is resized. I could use a series of handlers to check for size of field, text size, etc, but wondered if there is a more elegant way of updating the FormattedText value only when it changes.
Kaveh

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8143
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Detecting change to FormattedText

Post by FourthWorld » Sun Oct 18, 2020 10:17 am

If the field resizing is done with the pointer tool you can trap the resizeControl message.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5658
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Detecting change to FormattedText

Post by jacque » Sun Oct 18, 2020 6:31 pm

Offhand I can't see a way to avoid checking on every arrow key or mouse click, but you can streamline things by looking at the properties of the field.

Save "the properties of fld x" in a script local and when interactions occur, compare the current properties to the stored one. This is very fast. If they're different, save the new properties in the local variable and do whatever you need with the new configuration.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 452
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Detecting change to FormattedText

Post by kaveh1000 » Sun Oct 18, 2020 6:38 pm

Thank you Jacqueline. This is excellent. I had no idea about "the properties". I can see it creates an array. It's fast as you say, so no problem about checking with every arrow key or key press. :-)
Kaveh

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 452
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Detecting change to FormattedText

Post by kaveh1000 » Sun Oct 18, 2020 9:01 pm

Hi Jacqueline

As a follow-up, how do you compare two arrays? I tried

Code: Select all

if the properties of array_one is the properties of array_two...
but it is showing them not to be the same although they should be. I have a mental block with arrays. Any hints appreciated!
Kaveh

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

Re: Detecting change to FormattedText

Post by Klaus » Sun Oct 18, 2020 9:22 pm

Maybe just:

Code: Select all

if array_one = array_two
?

But I would probably only compare the HTMLTEXT of your field(s).
That will surely change when the formatting changes.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5658
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Detecting change to FormattedText

Post by jacque » Sun Oct 18, 2020 10:22 pm

Klaus is right, just check if tArray1 = tArray2.

@Klaus, checking only the htmltext won't catch if the field is resized.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 452
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Detecting change to FormattedText

Post by kaveh1000 » Sun Oct 18, 2020 10:33 pm

Thank you both. Always learn a lot here. I used "=" and it is not giving me the result intended so will do more testing. And will think about the HTMLText too...
Kaveh

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”