Code: Select all
put the short name of this cd into tRef
This line will cause a failure if any comment field has more than one instance of the search term in it. The second match will cause the handler to think it is done searching and it will exit prematurely. The foundchunk must be recoreded in the list, the way the original did, do ensure each line is unique.
Any change you make to the text of the field will be permanent, whether it is the color (my example) or the text style, or anything else. To get rid of the temporary styling, you can write a preOpenCard handler that removes it:
Code: Select all
on preOpenCard
put the text of fld "comment" into fld "comment"
end preOpenCard
That is a quick way to remove all styling. Another way to do the same thing is:
Code: Select all
set the textstyle of char 1 to -1 of fld "comment" to "plain"
Neither method will work if the field has other text styling already, because it will remove styles from all the text, not just the text that was found. If you need to remove the styling from only the found text, then you will need to save the list the handler created (in a global variable, a custom property, or a script local) and loop through it, resetting the style of the characters it recorded in the foundchunk. (Which is another reason to preserve the foundchunk in the list.)
If you don't want yellow text, you can set the box yourself by using the textstyle "box".
As you noticed, LiveCode's automatic boxed text only displays for a single found chunk at a time. If you want them all displayed simultaneously, you have to set textstyles the way we're doing it here.