FIND go back

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
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

FIND go back

Post by MaxV » Tue Sep 16, 2014 12:01 pm

Hi,
I like find behaviour: each time you call it, it continues from the last founded word.
Is there a way to go back with find ? I mean to go back to the previous founded text or find backward. :?:
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

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

Re: FIND go back

Post by dunbarx » Tue Sep 16, 2014 2:48 pm

Hi.

This derives from HC behavior, 27 years ago. The last "find", whether within a single field or anywhere on a stack of cards, is indexed internally. Similar to when one reads from an external file, the character where the last "read" ended is stored, and any subsequent read will resume from that point.

I do not think there is any way to do what you want unless you index yourself. But this is simple; store the foundChunk, or even a more complete pathway if on different cards with every successful find, in a custom property, and create a UI gadget to reveal the entire "found" history. This would be a fun and useful gadget to store in a library or plug-in. You will have to fake the find by selecting the foundChunk and changing its textStyle to "box", or whatever...

Craig Newman

EDIT:

You can access this history with a ready-made "undo", or rather "unFind", perhaps with a custom key combination, where the find sequence is reversed one by one instead of presenting the whole history.

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: FIND go back

Post by MaxV » Wed Sep 17, 2014 4:35 pm

At the present I solved this way, but I think that there are more elegant solutions:
button find:
########CODE#######
on mouseUp
#cerca avanti
find string the text of field "campocerca" in field "testo"
put the contCerca of button "bottoneCerca" into temp
add 1 to temp
set the contCerca of button "bottoneCerca" to temp
end mouseUp
#####END OF CODE#####

button find back:
########CODE#######
on mouseUp
#cerca indietro
put the contCerca of button "bottoneCerca" into temp
put temp - 1 into temp
if temp < 1 then
put 1 into temp
end if
set the contCerca of button "bottoneCerca" to temp
find empty in field "testo"
repeat for temp time
find string the text of field "campocerca" in field "testo"
end repeat
end mouseUp
#####END OF CODE#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

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

Re: FIND go back

Post by dunbarx » Wed Sep 17, 2014 6:06 pm

Hi.

Simon will forgive me. I just know it.

On a new card, make four buttons and a field. Put a bunch of different words in the field, but making sure that one word repeats several times. Let's make that word "XXX". Name the four buttons: "findNext", "findPrevious". "showHistory" and "clearHistory".

In the script of "findNext":

Code: Select all

on mouseUp
   find "XXX"
   set the foundHistory of this card to the foundHistory of this card & return & the foundChunk
end mouseUp
In "findPrevious"

Code: Select all

on mouseUp
   set the foundHistory of this cd to line 1 to -2 of the foundHistory of this cd
   get the last line of the foundHistory of this cd
   set the textstyle of it to "box"
end mouseup
In "showHistory"

Code: Select all

on mouseUp
   answer the foundHistory of this cd
end mouseUp
in "clearHistory"

Code: Select all

on mouseUp
   set the foundHistory of this card to ""
  set the textStyle of word 1 to 1000 of fld 1 to "plain"
end mouseUp
Start by clearing the history. Find one or two instances of the text. Check out the history. Go back a bit. Check out the history. Make this work nicer for you.

Craig

Post Reply