scroll field to a searched-for word

dunbarx at aol.com dunbarx at aol.com
Fri Apr 13 10:03:07 EDT 2012


Hi.


You can do this by using the "formattedText" to hard wrap the lines in your text field, so that the "lineOffset" function can find your text string. As an example, I made three fields. One (fld "fieldA") contains some original text with certain words that you might want to find in it, wrapped. The second (fld "fieldB") is a target field, and a third (fld "wordList") contains the actual words that you want to find. This is a locked list field.


In the list field, place:



on mouseup
   put the clickText into tText
   answer lineoffset(tText, fld "fielda")
   put fld "fielda" into fld "fieldb"
   set the text of fld  "fieldb" to the formattedText of fld "fieldb"
   answer lineoffset(tText, the formattedtext of fld "fieldb")
end mouseup


You should see that the first answer returns a smaller number than the second, since wrapping makes the number of visible lines larger than the actual number of lines in the field.


With this you can get the lineOffset of the found word in the formatted fld "fieldB" and use textHeight properties to scroll to the correct line. You will want to restore the unwrapped text back into the original after you are done.


I bet there are 


Craig Newman









-----Original Message-----
From: Nicolas Cueto <niconiko at gmail.com>
To: LiveCode - general LiveCode <use-livecode at lists.runrev.com>
Sent: Thu, Apr 12, 2012 8:41 pm
Subject: scroll field to a searched-for word


Hello All,

Most very likely, somewhere on the list can come up much faster than I
can with a method for this.

My stack has a vertically-scrollable text-field with a long text, and
a listbehavior field with a word on each cr-line. The effect I'm after
is, when a user searches for a word by clicking on the listbehavior
field, the text-field will get vertically scrolled to the line where
that word is.  Plus, if that word could get hilited, that would be a
nice bonus too.

Thank you in advance.

--
Nicolas Cueto

_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 



More information about the use-livecode mailing list