Setting hidden of lines very slow

hh hh at hyperhh.de
Mon Dec 3 11:45:45 EST 2018


> Hakan wrote:
> The code will not work if you have htmltext containing the text "color=" like:
> <p>To set the color you can use color="#fa3b42"</p>

Oh yes, was rather silly of me not to keep this in mind. There is a simple remedy:

put ("color=" is in fld 1) into isInField
if isInField then replace "color=" with numToChar(5) in fld 1 preserving styles
.. do the htmltext-method ..
if isInField replace numToChar(5) with "color=" in fld 1 preserving styles

what doesn't slow down if "color=" is in only a few lines.

> and you can also shave off some milliseconds in the styledText version by using foreach:
>> repeat for each key aKey in tTextA
>       # Check if first run has textcolor set
>       put (tTextA[aKey]["runs"][1]["style"]["textcolor"] is empty) \
>             into tTextA[aKey]["style"]["hidden"]
>  end repeat
>> For me that is always faster than your clever 'offset("color="…' version.

This may be true but the above doesn't work for the OP's question: To hide lines with
*any* textcolor property set, not only the textcolor for the whole line.

The styledText method is still very fast with the adjusted version below (make it better!).

For up to at about 2500 short lines the htmlText method is here still faster.
For more than 2500 short lines or if many text lines contain "color=" the styledText method
is faster.

The OP will simply take the version that is faster/better suited for his use case.

Here the two working methods that hide *exactly* the lines (more exactly: paragraphs)
of a field that contain no colored chunk.

-- styledText method
on mouseUp
  put the millisecs into m1
  lock screen; lock messages
  put the styledText of field "text" into st
  put st into tTextA
  repeat for each key aKey in tTextA
    put tTextA[aKey]["runs"] into T
    repeat for each key I in T
      put (T[I]["style"]["textcolor"] is empty) into tTextA[aKey]["style"]["hidden"]
    end repeat
  end repeat
  set the styledText of fld "text" to tTextA
  put the millisecs - m1 into fld "timing"
end mouseUp

-- htmlText method
on mouseUp
  put the millisecs into m1
  lock screen; lock messages
  put ("color=" is in fld 1) into isInField
  if isInField then
    replace "color=" with numTochar(1) in fld 1 preserving styles
  end if
  put the htmltext of fld 1 into ht
  set linedel to "<p"
  put the htmltext of fld 1 into ht
  replace " hidden" with empty in ht
  repeat for each line L in ht
    if offset("color=",L)>0 then
      put "<p" & L after s
    else put "<p hidden" & L after s
  end repeat
  set htmltext of fld 1 to  s
  if isInField then
    replace numTochar(1) with "color=" in fld 1 preserving styles 
  end if
  put the millisecs - m1 into fld "timing"
end mouseUp





More information about the use-livecode mailing list