Highlight instances of found text

7 messages Options
Embed this post
Permalink
Sivakatirswami

Highlight instances of found text

Reply Threaded More More options
Print post
Permalink
Does anyone have a function that will highlight/colorize instances of
found text in a field?

e.g. say we have a search function, user types "chapati"

In the particular ebook I have, all instances (lines or paragraphs
containing) of "chapati" are "gathered" and then posted to a field for
review... I would like to have all instance of "chapati" in that field
be highlighted or colorized.

I'm sure I can figure it out but someone I'm sure has already cooked
this dosai before and I'm a fan of using recipes.

Thanks
Sivakatirswami
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
dunbarx

Re: Highlight instances of found text

Reply Threaded More More options
Print post
Permalink
The "textColor" (or "foreGroundColor") can be set for a chunk expression,
so you can collect your found text and then set each instance to the color of
your choice.

Craig Newman


**************
A Good Credit Score is 700 or Above. See yours in
just 2 easy steps!
(http://pr.atwola.com/promoclk/100126575x1221323013x1201367230/aol?redir=http://www.freecreditreport.com/pm/default.aspx?sc=668072&
hmpgID=62&bcd=JulystepsfooterNO62)
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Mark Swindell

Re: Highlight instances of found text

Reply Threaded More More options
Print post
Permalink
In reply to this post by Sivakatirswami
Something like this ought to work:

ON mouseUp
     REPEAT WITH x = 1 to the number of words in field 1
         IF word x of field 1 is theFoundWord THEN
             set the backgroundcolor of  word x of field 1 to yellow
         END IF
     END repeat
END mouseUp

hth,
Mark


On Jul 4, 2009, at 4:41 AM, Sivakatirswami wrote:

> Does anyone have a function that will highlight/colorize instances  
> of found text in a field?
>
> e.g. say we have a search function, user types "chapati"
>
> In the particular ebook I have, all instances (lines or paragraphs  
> containing) of "chapati" are "gathered" and then posted to a field  
> for review... I would like to have all instance of "chapati" in that  
> field be highlighted or colorized.
>
> I'm sure I can figure it out but someone I'm sure has already cooked  
> this dosai before and I'm a fan of using recipes.
>
> Thanks
> Sivakatirswami
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Sivakatirswami

Re: Highlight instances of found text

Reply Threaded More More options
Print post
Permalink
Mark Swindell wrote:

> Something like this ought to work:
>
> ON mouseUp
>     REPEAT WITH x = 1 to the number of words in field 1
>         IF word x of field 1 is theFoundWord THEN
>             set the backgroundcolor of  word x of field 1 to yellow
>         END IF
>     END repeat
> END mouseUp
>
> hth,
> Mark

Thanks Mark... this almost works

1) only works for single words

2) and one must use "contains" if you want to pick up everything bounded
by punctuation
and part of hyphenated words.

ON mouseUp
    REPEAT WITH x = 1 to the number of words in field 1
        IF word x of field 1 contains theFoundWord THEN
            set the backgroundcolor of  word x of field 1 to yellow
        END IF
    END repeat
END mouseUp

3) But fails for any strings with spaces in it.  I'm cogitating how to
do just as efficient a loop to target matching string chunks, but will
probably need to sleep on it first (smile)... I think I have an looping
off set function somewhere that should work...

I need to get more organized with my library of already build tools!








>
>
> On Jul 4, 2009, at 4:41 AM, Sivakatirswami wrote:
>
>> Does anyone have a function that will highlight/colorize instances of
>> found text in a field?
>>
>> e.g. say we have a search function, user types "chapati"
>>
>> In the particular ebook I have, all instances (lines or paragraphs
>> containing) of "chapati" are "gathered" and then posted to a field
>> for review... I would like to have all instance of "chapati" in that
>> field be highlighted or colorized.
>>
>> I'm sure I can figure it out but someone I'm sure has already cooked
>> this dosai before and I'm a fan of using recipes.
>>
>> Thanks
>> Sivakatirswami
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Peter Brigham MD

Re: Highlight instances of found text

Reply Threaded More More options
Print post
Permalink
In reply to this post by Sivakatirswami
I'm a little late to this party, Sivakatirswami, but if you haven't  
found something better, try this. (The offsets function is quite fast;  
it's one of my utility functions when I need all instances of a string  
in a text block.)

on colorize tString, fldRef
    put length(tString) into tLen
    put the text of fldRef into tText
    put offsets(tString,tText) into oList
    if oList = 0 then exit colorize
    repeat for each item i in oList
        set the textColor of char i to i+tLen-1 of fldRef to 247,9,9
        -- or whatever color you like
    end repeat
end colorize

on revertToBlack fldRef
    set the textColor of char 1 to -1 of fldRef to black
end revertToBlack

function offsets str,@cntr
   -- returns a comma-delimited list of all the offsets of str in cntr
    -- cntr is passed by reference to avoid unnecessary duplication
    -- of very large text blocks in memory
    -- cntr contents are not altered by this function
    if str is not in cntr then return 0
    put "" into osList
    put 0 into startPoint
    repeat
       put offset(str,cntr,startPoint) into os
       if os = 0 then exit repeat
       add os to startPoint
       put startPoint & comma after osList
    end repeat
    delete last char of osList
    return osList
end offsets

If you want only whole words colorized, you can use this:

on colorizeWords tString, fldRef
    put the text of fldRef into tText
    put the number of words of tString into L
    put wordOffsets(tString,tText) into oList
    if oList = 0 then exit colorizeWords
    repeat for each item i in oList
       if word i of tText <> tString then next repeat
       set the textColor of word i to i+L-1 of fldRef to 247,9,9
       -- or whatever color
    end repeat
end colorizeWords

function wordOffsets str,@cntr
    -- returns a comma-delimited list of all the wordoffsets of str in  
cntr
    -- not limited to whole words (will catch str as part of a word)
    -- cntr is passed by reference to avoid unnecessary duplication
    -- of very large text blocks in memory
    -- cntr contents are not altered by this function
    put offsets(str,cntr) into charList
    if charList = 0 then return 0
    put "" into woList
    repeat for each item i in charList
       put the number of words of (char 1 to i of cntr) & "," after  
woList
    end repeat
    delete char -1 of woList
    return woList
end wordOffsets

You can add caseSensitive = true if you like.

One caveat about the word colorizing routine -- Rev is idiosyncratic  
in defining anything enclosed by quotes as a single word. (Why?? If  
you command-right-arrow to step through words of a text, Rev knows to  
treat quotation marks as just another character and will move from  
word to word the way any other text app does, so the engine knows what  
the usual definition of a word is. Bug report anyone?) To colorize all  
words including those within a quotation, you have to first replace  
the quote character by some other character in the field, then restore  
the quotes.

(The obvious remaining utility functions, itemOffsets() and  
lineOffsets(), are left as an exercise for the reader, but are quite  
handy to have in a library.)

HTH,

-- Peter

Peter M. Brigham
[hidden email]
http://home.comcast.net/~pmbrig



On Jul 3, 2009, at 10:41 PM, Sivakatirswami wrote:

> Does anyone have a function that will highlight/colorize instances  
> of found text in a field?
>
> e.g. say we have a search function, user types "chapati"
>
> In the particular ebook I have, all instances (lines or paragraphs  
> containing) of "chapati" are "gathered" and then posted to a field  
> for review... I would like to have all instance of "chapati" in that  
> field be highlighted or colorized.
>
> I'm sure I can figure it out but someone I'm sure has already cooked  
> this dosai before and I'm a fan of using recipes.
>
> Thanks
> Sivakatirswami

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Sivakatirswami

Re: Highlight instances of found text

Reply Threaded More More options
Print post
Permalink
Aloha and Namaste, Peter

Thank you!  this is very helpful... it's what I was looking for, but my
string manipulation skills are not as strong as yours and I defaulted to
the old "hack" which is to use find and then FoundChunk, which always
*seems* to work well, but often introduces some unsolvable gremlin.  
e.g. my function passes all lines/Paragraphs containing the search
string to a field for review, highlighting every instance of the found
text. The user can then print this out after editing it.

Using "Supreme Being" it found all the instances, but for some
mysterious reason highlighted all instances except

"Supreme Being;

where the phrase was  bounded by a quotation mark and a semi colon, the
find function will not find that string a such if "find whole" is
used... but your routine surely will...

I will try yours instead.

I offer the user both options "Partial Match" (any string in any
location) or "Whole words" so I can use both of these routines Thanks!

# example of the "Find... Foundchunk" "hack"



on gatherRefs
# set the next instance hilite color back to light blue
   Global gHiliteColorNo
   put 1 into gHiliteColorNo
   push card
 
   ask "What topic?"
   if it is empty then exit gatherRefs
   put it into jai
   Put "REFERENCES TO " "e& Jai "e& " in the Saiva Dharma
Shastras" & cr &cr into Output
 
   repeat with x = 2 to (the number of cards of this stack)
      if (fld "paraSubject" of cd x contains jai) or  (fld "text" of cd
x  contains jai) then
         put fld "ParaNumber" of cd x && fld "ParaSubject" of cd x &cr&
fld "text" of cd x & cr & cr after output
      end if
   end repeat
 
 
   Put "GLOSSARY REFERENCES" & " TO " "e& Jai "e& " in the Saiva
Dharma Shastras"&  cr & cr  after output
 
   open stack "glossary"
 
   repeat with x = 1 to (the number of cards of this stack)
      put fld "text" of card x into tEntries
      repeat for each line y in tEntries
         if y contains jai then put y & cr & cr after tGlossaryResults
      end repeat
   end repeat
 
   if tGlossaryResults <> empty then
      put tGlossaryResults after output
   else
      put "--NONE" after output
   end if
 
 
   close stack "glossary"
 
 
 
   put output into fld "ref-text" of cd 1 of stack "read references"
   open stack "Read References"
   put jai into fld "readRef_StringToFind"
 repeat until FoundIt is empty
      find whole jai in fld "ref-Text"
      put the foundChunk into FoundIt
      if foundIt is not empty then
         set the backgroundcolor of foundit to yellow
      end if
   end repeat
     set the scroll of fld "ref-text" to 0
     pop card
     toplevel stack "Read References"
 
 
end gatherRefs

Peter Brigham MD wrote:

> I'm a little late to this party, Sivakatirswami, but if you haven't
> found something better, try this. (The offsets function is quite fast;
> it's one of my utility functions when I need all instances of a string
> in a text block.)
>
> on colorize tString, fldRef
>    put length(tString) into tLen
>    put the text of fldRef into tText
>    put offsets(tString,tText) into oList
>    if oList = 0 then exit colorize
>    repeat for each item i in oList
>        set the textColor of char i to i+tLen-1 of fldRef to 247,9,9
>        -- or whatever color you like
>    end repeat
> end colorize
>
> on revertToBlack fldRef
>    set the textColor of char 1 to -1 of fldRef to black
> end revertToBlack
>
> function offsets str,@cntr
>   -- returns a comma-delimited list of all the offsets of str in cntr
>    -- cntr is passed by reference to avoid unnecessary duplication
>    -- of very large text blocks in memory
>    -- cntr contents are not altered by this function
>    if str is not in cntr then return 0
>    put "" into osList
>    put 0 into startPoint
>    repeat
>       put offset(str,cntr,startPoint) into os
>       if os = 0 then exit repeat
>       add os to startPoint
>       put startPoint & comma after osList
>    end repeat
>    delete last char of osList
>    return osList
> end offsets
>
> If you want only whole words colorized, you can use this:
>
> on colorizeWords tString, fldRef
>    put the text of fldRef into tText
>    put the number of words of tString into L
>    put wordOffsets(tString,tText) into oList
>    if oList = 0 then exit colorizeWords
>    repeat for each item i in oList
>       if word i of tText <> tString then next repeat
>       set the textColor of word i to i+L-1 of fldRef to 247,9,9
>       -- or whatever color
>    end repeat
> end colorizeWords
>
> function wordOffsets str,@cntr
>    -- returns a comma-delimited list of all the wordoffsets of str in
> cntr
>    -- not limited to whole words (will catch str as part of a word)
>    -- cntr is passed by reference to avoid unnecessary duplication
>    -- of very large text blocks in memory
>    -- cntr contents are not altered by this function
>    put offsets(str,cntr) into charList
>    if charList = 0 then return 0
>    put "" into woList
>    repeat for each item i in charList
>       put the number of words of (char 1 to i of cntr) & "," after woList
>    end repeat
>    delete char -1 of woList
>    return woList
> end wordOffsets
>
> You can add caseSensitive = true if you like.
>
> One caveat about the word colorizing routine -- Rev is idiosyncratic
> in defining anything enclosed by quotes as a single word. (Why?? If
> you command-right-arrow to step through words of a text, Rev knows to
> treat quotation marks as just another character and will move from
> word to word the way any other text app does, so the engine knows what
> the usual definition of a word is. Bug report anyone?) To colorize all
> words including those within a quotation, you have to first replace
> the quote character by some other character in the field, then restore
> the quotes.
>
> (The obvious remaining utility functions, itemOffsets() and
> lineOffsets(), are left as an exercise for the reader, but are quite
> handy to have in a library.)
>
> HTH,
>
> -- Peter
>
> Peter M. Brigham
> [hidden email]
> http://home.comcast.net/~pmbrig
>
>
>
> On Jul 3, 2009, at 10:41 PM, Sivakatirswami wrote:
>
>> Does anyone have a function that will highlight/colorize instances of
>> found text in a field?
>>
>> e.g. say we have a search function, user types "chapati"
>>
>> In the particular ebook I have, all instances (lines or paragraphs
>> containing) of "chapati" are "gathered" and then posted to a field
>> for review... I would like to have all instance of "chapati" in that
>> field be highlighted or colorized.
>>
>> I'm sure I can figure it out but someone I'm sure has already cooked
>> this dosai before and I'm a fan of using recipes.
>>
>> Thanks
>> Sivakatirswami
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Wilhelm Sanke, FB01

Re: Highlight instances of found text

Reply Threaded More More options
Print post
Permalink
In reply to this post by Sivakatirswami
On Wed Jul 8, 2009, Sivakatirswami katir at hindu.org wrote:


 

> Aloha and Namaste, Peter
>
> Thank you!  this is very helpful... it's what I was looking for, but my
> string manipulation skills are not as strong as yours and I defaulted to
> the old "hack" which is to use find and then FoundChunk, which always
> *seems* to work well, but often introduces some unsolvable gremlin.  
> e.g. my function passes all lines/Paragraphs containing the search
> string to a field for review, highlighting every instance of the found
> text. The user can then print this out after editing it.
>
> Using "Supreme Being" it found all the instances, but for some
> mysterious reason highlighted all instances except
>
> "Supreme Being;
>
> (snip)


It may be additionally worthwhile to have a look at the scripts of my  
"Hypertext Annotations" stack (2004), where searched strings are
highlighted irrespective of other leading or trailing characters.

<http://www.sanke.org/Software/HypertextAnnotations.zip>

Regards,

Wilhelm Sanke

<http://www.sanke.org/MetaMedia>
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution