scroll field to a searched-for word
dunbarx at aol.com
dunbarx at aol.com
Fri Apr 13 10:16:36 EDT 2012
As I said, "I bet there are". And I was right. This came from somebody in a past discussion.
Make another field with lots of text in it. Make this mostly wrapped text. Lock the field, and put this in it:
on mouseUp
put word 2 of the clickCharChunk into myPos
put the formattedText of fld 2 into myText
put number of lines of (char 1 to myPos of myText) into myLineNr
answer myLineNr
end mouseUp
This smacks of Jacque, but not sure. Anyway, this should give you another insight into how to make your gadget work. Again, it uses the formattedText to hard wrap those pesky lines that hide the actual number of lines in the field.
Craig Newman
-----Original Message-----
From: dunbarx <dunbarx at aol.com>
To: use-livecode <use-livecode at lists.runrev.com>
Sent: Fri, Apr 13, 2012 10:05 am
Subject: Re: scroll field to a searched-for word
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
_______________________________________________
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