Page 1 of 1
Search & hilite different lines in scrolling field
Posted: Sun Dec 26, 2021 7:38 pm
by Fjord
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?
Re: Search & hilite different lines in scrolling field
Posted: Sun Dec 26, 2021 10:36 pm
by richmond62
-
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
Re: Search & hilite different lines in scrolling field
Posted: Mon Dec 27, 2021 1:56 am
by FourthWorld
Select will change the selection to what you set it to. What you're looking for is the hilitedLines property.
Re: Search & hilite different lines in scrolling field
Posted: Mon Dec 27, 2021 4:41 am
by dunbarx
I may be misunderstanding , but what about this.
Craig
Re: Search & hilite different lines in scrolling field
Posted: Mon Dec 27, 2021 11:46 am
by Fjord
@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!
Re: Search & hilite different lines in scrolling field
Posted: Mon Dec 27, 2021 1:02 pm
by jmburnod
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
Re: Search & hilite different lines in scrolling field
Posted: Mon Dec 27, 2021 3:53 pm
by FourthWorld
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.
Re: Search & hilite different lines in scrolling field
Posted: Mon Dec 27, 2021 7:15 pm
by Fjord
@Richard: I was focusing on the 'select' strategy and missed the 'hilite' strategy
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!