Speeding a handler?
Phil Davis
revdev at pdslabs.net
Tue Dec 1 12:15:43 EST 2009
Hello Ton,
This should be MUCH faster because the text is moved to a variable for
processing. It assumes all text in the field is either red or black.
on mouseUp
put 1 into someFld -- I used fld 1 in my test
-- get colored text from field
put the htmlText of fld someFld into tText
-- remove quote char from html (but leave " entity)
replace quote with empty in tText
-- remove all red color from text
replace "<font color=#FF0000>" with empty in tText
replace "</font>" with empty in tText
-- set text line color to red if line contains a quote
repeat for each line tLine in tText
if """ is in tLine -- this line contains a quote
then -- make the text red
put "<font color=#FF0000>" after char 3 of tLine -- after "<p>"
put "</font>" before char -4 of tLine -- before "</p>"
end if
put tLine & cr after tNewText
end repeat
delete last char of tNewText
-- update the field with recolored text
lock screen
put the vScroll of fld someFld into x
set the htmlText of fld someFld to tNewText
set the vScroll of fld someFld to x
unlock screen
end mouseUp
HTH -
Phil Davis
Ton Cardona wrote:
> I have a text field with 5.729 lines. 826 of them, those containing quotes, must appear coloured in red so the instruction would be:
>
> put 0 into x
> repeat for each line aLine of fld someFld
> add 1 to x
> if quote is in aLine then
> set the forecolor of line x of fld someFld to "red"
> replace quote with empty in line x of fld someFld
> end if
> end repeat
>
> The problem is it takes 55 seconds.
>
> I have reduced this time to 33 seconds by recording previously the numbers of the lines to be coloured and storing them in a customProp, yet it still takes 33 seconds.
>
> Does anyone know a faster way of performing this task?
>
> Thanks in advance,
>
> Ton
>
--
Phil Davis
PDS Labs
Professional Software Development
http://pdslabs.net
More information about the use-livecode
mailing list