The effective attribute is what I was looking for. As Paul mentioned, if you 
just say “set the background of… to hiliteColor” you don’t get anything. But if 
you set it to the “effective hiliteColor” you get the system default (btw, I 
tried “system hiliteColor” but LC treats it as a syntax error. Pity, since 
“system” in this case makes more sense to me than effective. But that’s another 
story…)

I was intrigued by Pauls example of trying to set some highlighting that 
“sticks” but that still gives the user the illusion that nothing unusual is 
going on ie. If you select another portion of text, the first selection 
unhighlights, of if you click in the field the highlighting goes away, but you 
can click in other fields and it doesn’t. I saw it as a challenge to try and 
get that working. He probably has more elegant code than I do but the following 
comes very close, I hope, to the solution he was describing. The biggest 
challenge I found is that when you have a selection in the field, and you go to 
change it to some other text the normal behaviour is to have the first 
selection immediately disappear. That doesn’t happen if you are depending on a 
selectionChanged message since you don’t actually get that until the end of the 
2nd selection and you need the old one to disappear when you start the 2nd 
selection. I solved that by having an openField handler that just checks to see 
if there is a selection, and if there is, removes it. openField happens 
immediately and before selectionChanged is sent. I can’t remember at the moment 
why I left the removal in both handlers, but it seems it was necessary for some 
combination of clicks or selections. I’d have to go back and test that again. 


on openField
   -- a selection is potentially about to begin
   -- see if there is already a selection in the field and unhighlight it
   put the cpChunkExpression of field "fld1" into chunkExp
   if chunkExp is not empty then
      set the backgroundcolor of chunkExp to "" -- gets rid of our fake 
highlighting
      set the cpChunkExpression of field "fld1" to empty
   end if
end openField

on selectionChanged
   -- get the current highlight color
   put the effective hiliteColor of field "fld1" into tHiliteColor
   -- then initialize our new chunk expression
   put the selectedChunk of fld "fld1" into newChunkExp
   -- determine if there is an old chunk we need to unhighlight
   put the cpChunkExpression of field "fld1" into chunkExp
   if chunkExp is not empty then
      set the backgroundcolor of chunkExp to "" -- gets rid of our fake 
highlighting
      set the cpChunkExpression of field "fld1" to empty
   end if
   -- now, with regards to the new chunk expression there are 3 possibilities
   -- 1. its empty, in which case we do nothing
   -- 2. its just an insertion point, in which case we do nothing (ie. word 2 
of newChunkExp > word 4)
   -- 3. But, if word 2 and word 4 of newChunkExp define a range of text, 
highlight it
   if word 2 of newChunkExp < word 4 of newChunkExp then
      set the backgroundcolor of newChunkExp to tHiliteColor
      -- and save it for future reference
      set the cpChunkExpression of field "fld1" to newChunkExp
   end if
   -- if we want to unhighlight everything we can just click anywhere in the 
field
end selectionChanged



> On 14 Jul 2023, at 9:39 pm, J. Landman Gay via use-livecode 
> <use-livecode@lists.runrev.com> wrote:
> 
> On 7/14/23 11:14 AM, Mark Smith via use-livecode wrote:
>> BTW, is there a way of determining the default highlight colour?
> 
> The dictionary says: "By default, the global hiliteColor property is set to 
> the system highlight color."
> 
> I'd guess yours is blue. That's pretty standard on Mac.
> 
> -- 
> Jacqueline Landman Gay         |     jac...@hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to