Search & hilite different lines in scrolling field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Fjord
Posts: 145
Joined: Sat Dec 06, 2008 6:18 pm

Search & hilite different lines in scrolling field

Post by Fjord » Sun Dec 26, 2021 7:38 pm

I guess there's a simple solution but I couldn't find it:
I have
- a scrolling fld with "Multiple hilites" checked
- a search fld with "Don't search" checked and a "returnInField" handler.
I want to hilite all relevant, possibly non contiguous, lines of the scrolling fld, that contain the search string.

Of course I can do that manually, holding down the command key to hilite several lines. I tried to do the same by script; after many trials, this is the cleanest version:

Code: Select all

         find string laChaine in fld leNumero   -- search 1st occurrence
         repeat while the result ≠ "Not found"
            select the foundLine -- hilite it; that works
            find string laChaine in fld leNumero -- search next occurrence; but stays on 1st one  :-(
         end repeat
but this code
1) keeps flashing the very same line of the scrolling fld
2) therefore, never stops.

How does one do that?
--
François

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Search & hilite different lines in scrolling field

Post by richmond62 » Sun Dec 26, 2021 10:36 pm

Screenshot_2021-12-26_22-26-44.png
-

Code: Select all

on mouseUP
put 1 into KOUNT
repeat until line KOUNT of fld "slf" is empty
set the backGroundColor of line KOUNT of fld "slf" to red
add 2 to KOUNT
end repeat
end mouseUP
Attachments
stripey.livecode.tar.gz
Here's the stack.
(660 Bytes) Downloaded 156 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Search & hilite different lines in scrolling field

Post by FourthWorld » Mon Dec 27, 2021 1:56 am

Select will change the selection to what you set it to. What you're looking for is the hilitedLines property.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Search & hilite different lines in scrolling field

Post by dunbarx » Mon Dec 27, 2021 4:41 am

I may be misunderstanding , but what about this.

Craig
HiliteX.livecode.zip
(1020 Bytes) Downloaded 155 times

Fjord
Posts: 145
Joined: Sat Dec 06, 2008 6:18 pm

Re: Search & hilite different lines in scrolling field

Post by Fjord » Mon Dec 27, 2021 11:46 am

@Richard
Select will change the selection to what you set it to
I guessed so :-) (and checked)
What you're looking for is the hilitedLines property
Not really: my problem is to select the lines, non contiguous. HilitedLines is for getting them once they're selected, and I checked and it works.

@Craig & Richmond: what I seem to understand from your solutions is 'just paint the lines you select' with 'set the backColor of line xxx to whatever colour you like'. Then check the color of each line to implement 'get the hilitedLines'. While I was trying to use the 'selection' feature of LC…
BTW, it seems best to uncheck the selection features of the fld (see attached, if you care to)
Thanks!
Attachments
HiliteX.livecode.zip
(1.13 KiB) Downloaded 152 times
--
François

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Search & hilite different lines in scrolling field

Post by jmburnod » Mon Dec 27, 2021 1:02 pm

Bonjour François,
Not really: my problem is to select the lines, non contiguous.
You can do this, just set the NoContiguousHilite of the list field to true.
Best regards
Jean-Marc
https://alternatic.ch

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Search & hilite different lines in scrolling field

Post by FourthWorld » Mon Dec 27, 2021 3:53 pm

Fjord wrote:
Mon Dec 27, 2021 11:46 am
@Richard
Select will change the selection to what you set it to
I guessed so :-) (and checked)
What you're looking for is the hilitedLines property
Not really: my problem is to select the lines, non contiguous. HilitedLines is for getting them once they're selected, and I checked and it works.
The hilitedLines property is also settable. I've used it for 30 years ever since it premiered in SuperCard, and have been enjoying its inclusion in LiveCode since 1998.

The example provided in the Dictionary is:

Code: Select all

set the hilitedLine of field "Options List" to 1
Loop to find the lineOffsets, collect those in a comma-delimited string, set the hilitedLines, (and note the tStartLine option for lineOffset):

Code: Select all

-- To call, as from a button, here looking for "the" in the list:
on mouseUp
    HiliteMatchingLines "the", the long id of fld 1
end mouseUp

-- The handler itself:
on HiliteMatchingLines pStringToFind, pFieldObj
   put the text of pFieldObj into tText
   put 0 into tStartLine
   repeat
      put lineOffset(pStringToFind, tText, tStartLine) into tLineN
      if tLineN = 0 then exit repeat
      add tLineN to tStartLine
      put tStartLine &"," after tFoundLines
   end repeat
   set the hilitedLines of pFieldObj to tFoundLines
end HiliteMatchingLines
And Jean-Mark's guidance is also valuable: the NonContiguousHilites is a must here if you want to also support manual selection.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Fjord
Posts: 145
Joined: Sat Dec 06, 2008 6:18 pm

Re: Search & hilite different lines in scrolling field

Post by Fjord » Mon Dec 27, 2021 7:15 pm

@Richard: I was focusing on the 'select' strategy and missed the 'hilite' strategy :oops: :cry:
Thanks a lot!! that's neat!
I played a little bit with the 'HiliteX' example stack from Craig, just inserted one line in your script, so that a user can freely mix manual selection and script selection (attached just in case someone is interested in the future):

Code: Select all

-- Richard's example script
on HiliteMatchingLines pStringToFind, pFieldObj
  put the hilitedLines of pFieldObj & comma into tFoundLines -- I just inserted this line
  put the text of pFieldObj into tText
…etc
  set the hilitedLines of pFieldObj to tFoundLines -- get the unique hilited lines nicely ordered  :o :-)
end HiliteMatchingLines
The nice thing there is, although the variable 'tFoundLines' gets a bit messy with some lines listed several times, in the end the last lines gets everything nice and tidy.
Thanks to all for your help!
Attachments
HiliteX.livecode.zip
(1.57 KiB) Downloaded 167 times
--
François

Post Reply