Page 1 of 1

HilitedLines only for list fields?

Posted: Fri Mar 04, 2022 10:40 pm
by dunbarx
I have a gadget that, when I select a block of lines in the SE, sets the backColor of that block to pink. This simplifies finding it again if I need to wander off in a long script. I originally had to insert a string, say "XXXX" at both the top and bottom of that text segment. It was easy to find those two strings, and they delineated the start and end lines of interest.

It occurred to me that what I really wanted was to select that text block and simply hit a button. But since the field in the SE is NOT a list field, the hilitedLines property does not work. I have to:

Code: Select all

 if there is a stack "revNewScriptEditor 1" then
            put word 2 of the selectedChunk into StartChar
            put word 4 of the selectedChunk into EndChar
            put word 7 of the selectedChunk into tField
            put the number of lines of char 1 to StartChar of fld tField of stack "revNewScriptEditor 1" into startLine
            put the number of lines of char 1 to EndChar of fld tField of stack "revNewScriptEditor 1" into endLine
            set the backColor of line startLine to endLine of fld tField of stack "revNewScriptEditor 1" to "255,215,255"
         end if
I am not complaining, mind you, but isn't there a one-liner for all that? In other words, isn't there a "hilitedLines" for "ordinary" editable fields?

Craig

Re: HilitedLines only for list fields?

Posted: Fri Mar 04, 2022 10:47 pm
by dunbarx
Oh, never mind. I had tried the "selectedLine", but did it badly.

I did it better just a minute ago. :roll:

Crag

Re: HilitedLines only for list fields?

Posted: Fri Mar 04, 2022 11:08 pm
by dunbarx
Anyway, I do not see the need for both the "hilitedLines" and the "selectedLines", even though one is a property and the other a function.

It seems that one comprehensive function would do. It was not for compatibility with HC, since the selectedLine in HC only worked on single lines, and there was no "hilitedLines" property.

Craig

Re: HilitedLines only for list fields?

Posted: Fri Mar 04, 2022 11:21 pm
by dunbarx
Glad that there was just a little more than wasted time here. If a block of text is selected in the SE, and the following code is somewhere:

Code: Select all

 if there is a stack "revNewScriptEditor 1" then
            answer the selectedLines
            set the backColor of the selectedLines to "255,215,255"
         end if
The block in question is tinted, but so is the line just below. In other words, if Line 10 to 20 is selected, lines 10 to 21 are colored. I am not "catching" the return in the bottommost line. This happens if even one char in line 20 is selected.

Easy to get around this, but it kills the one-liner. But why?

Craig

Re: HilitedLines only for list fields?

Posted: Sat Mar 05, 2022 6:25 pm
by jacque
I suppose because the selectedLine refers to the whole line regardless of how much of it is actually selected.

Edit: You can use the selectedChunk instead to avoid the trailing return.

Re: HilitedLines only for list fields?

Posted: Mon Mar 07, 2022 1:36 am
by dunbarx
Jacque.

I used the selectedChunk in my first post. The issue is with the "selectedLines". The value returned from that function is one thing. What is changed is one additional line.

Craig

Re: HilitedLines only for list fields?

Posted: Mon Mar 07, 2022 6:37 pm
by jacque
I meant that this one-liner should work:

Code: Select all

set the backcolor of the selectedChunk to "pink" 
But if you catch the trailing return then you're in the same boat again.

Re: HilitedLines only for list fields?

Posted: Mon Mar 07, 2022 6:46 pm
by jacque
Selectedlines and hilitedlines have different behaviors. Off the top of my head, hilitedlines are meant specifically for lists and menus. In lists they are persistent, whereas selections are transient. Hilitedlines select the entire line, right to the edge of the field, including the trailing return, where selections (but apparently not selectedlines) only select the actual text of the line. There may be other differences I'm forgetting.

Re: HilitedLines only for list fields?

Posted: Mon Mar 07, 2022 7:06 pm
by dunbarx
Jacque.

Ah, I see what you mean, and that worked. So it is just something odd about the selectedLines. So with a field with a handful of lines, and this in a button script;

Code: Select all

on mouseUp
   set the backcolor of fld 1 to "255,255,255" 
   select line 2 to 3 of fld 1
    set the backcolor of the selectedChunk to "pink" -- colors lines 2,3
    wait 44
   set the backcolor of the selectedlines to "pink"    -- colors lines 2,3,4
end mouseUp
Craig

Re: HilitedLines only for list fields?

Posted: Tue Mar 08, 2022 6:54 pm
by jacque
I think it's a byproduct of how LC treats chunk delimiters, similar to the complaints about trailing commas in lists. The trailing delimiter is part of the line, not a separator between lines. If you specify lines, you'll get the delimiter. If you specify chars (chunks) you won't.

BTW, due to property inheritance, setting the backcolor of the field won't affect the backcolor of the text. To clear the colors you'd need to specify a text chunk. I usually do this:

Code: Select all

set the backcolor of char 1 to - 1 of fld 1 to "255,255,255" 
You probably knew that.

Re: HilitedLines only for list fields?

Posted: Tue Mar 08, 2022 8:32 pm
by dunbarx
Jacque.

Yes and no. You ought to check out the bottom of:
viewtopic.php?f=9&t=36811&p=213478#p213478

Craig

Re: HilitedLines only for list fields?

Posted: Tue Mar 08, 2022 8:50 pm
by jacque
Hm. I've never had to refocus to reset the color. Maybe I never had the exact conditions necessary to require it.