My Bold Script is slow

Ian Summerfield iansummerfield at btconnect.com
Sat Feb 9 19:10:01 EST 2002


On 9/2/02 11:01 pm, "Björnke von Gierke" <bvg at mac.com> scribed:

> Hey thats a cool solution, but unfortunately it will deselect the text!
> As it is not working with the selection it is not applicable for me,
> what is realy regretable, couse that's realy a fast solution.
> Anyway, I have found a pretty fast solution myself, and am not longer in
> need of a faster way of removing styles. If anyone else has a similar
> problem, I added the script below:
> 
> on mouseUp
>  put "bold" into myStyle
>  lock screen --this speeds things extremly up!
> 
>  repeat with myChar = the second word of the selectedChunk to \
>           the fourth word of the selectedChunk


Well I can't take any credit for the superb solution, but I can see it's
easily modified not to deselect the text:

on mouseUp
   put the selectedChunk into rememberChunk
   put the htmltext of the selectedChunk into var1
   replace "<b>" with "" in var1
   replace "</b>" with "" in var1
   do "select "& rememberChunk
   set the htmltext of the selection to var1
   do "select "& rememberChunk
end mouseUp

It wouldn't be too hard to rewrite it as a function taking parameters for
bold, underline, etc.  As a bonus the solution above is now able to work on
whatever text is selected regardless of which field it's in!

BTW: It's still bad coding practice to use calculations in a loop,  each
iteration of the loop will cause those calculations to have to be re-done,
it will also make you code difficult to maintain.  If for any reason in the
future someone modifies your code to change the selection during one of the
loop passes then "the fourth word of the selectedChunk" could change it's
value - spelling disaster.  I got my knuckles wrapped for doing such things
when I first worked in Apple USA on Applelink Offline!  Take my work for it,
if you can get into the habit of putting things slightly longer it will be
more efficient, but safer!

Put the second word of the selectedChunk into startloop
Put the fourth word of the selectedChunk into endloop
repeat with myChar = startloop to endloop
  -- now it's safe to do things like "select line 1 to 5 of ..."
End repeat
          



-i-




More information about the use-livecode mailing list