On Mittwoch, Apr 2, 2003, at 20:16 Europe/Zurich, [EMAIL PROTECTED] wrote:
...
Perhaps it might be worth someone's while
to write a style-applying handler that does not display this behavior?
...

Well I have a very old script which does exactly that. It was one of the first scripts that I ever wrote to use it (not only to learn the language). I remember splitting it up to work around the script limit, and also remember to set the traversalOn of the button to false. This example is with italic, there is only one occurrence of "italic" that needs to be changed. It is probably extremely bad done and/or slow (I remember finding it fast enough for my task), but it might be a starting point for you to improve upon (start with the repeat loops, "repeat for each <chunktype>..." is much faster then "repeat with...", and some "exit repeat" are in order). Oh and look out for wrapped lines!
comments added now.



on mouseUp
put "text" into myField --this is the name of the field your styled text is in
put "italic" into myStyle --change here for other styles
if the textstyle of the selection contains myStyle then --faster way, style not "mixed"
put the textstyle of the selection into myCurrentStyle
delete item itemoffset(myStyle, myCurrentStyle) myCurrentStyle
set the textstyle of the selection to myCurrentStyle
else --slower way
repeat with myChar = the second word of the selectedChunk to the fourth word of the selectedChunk
if the textstyle of char mychar of field "text" contains myStyle then --italic is present
add one to styleCount
end if
end repeat
if styleCount > (the number of chars in the selection) / 2 then --remove style/add style switch
styleChar myStyle, myField, "remove"
else
styleChar myStyle, myField, "add"
end if
end if
end mouseUp


on styleChar myStyle, myField, myMode
--now the complexity increases, this is quiet streamlined for the 10 line limit
--the clue here generally is that single chars do NOT return "mixed" in their style
--i am too tired too comment all of this, ask if there are problems
lock screen
repeat with myChar = the second word of the selectedChunk to the fourth word of the selectedChunk
put the textStyle of char myChar of card field myField into myCurrentStyle
put myChar into mySecChar
repeat while the textStyle of char mySecChar+1 of field myField = myCurrentStyle and mysecchar < the number of chars in the selection
--skipping all chars with the same style to change them all at once
add one to mySecChar
end repeat
if myStyle is in myCurrentStyle and myMode = "remove" then
delete item itemoffset(myStyle,myCurrentStyle) myCurrentStyle
set the textstyle of char myChar to mySecChar of field myField to myCurrentStyle
else if myStyle is not in myCurrentStyle and myMode = "add" then
if the textstyle of char myChar to mySecChar of field myField <> empty then
set the textstyle of char myChar to mySecChar of field myField to the textstyle of char myChar to mySecChar of field myField & ", " & myStyle --adding style
else
set the textstyle of char mychar to mySecChar of field myField to myStyle --style was plain
end if
end if
put mySecChar into myChar
end repeat
end StyleChar


_______________________________________________
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to