Re: Syntax Colouring
Re: Syntax Colouring
- Subject: Re: Syntax Colouring
- From: "M. Uli Kusterer" <email@hidden>
- Date: Tue, 29 Jul 2003 16:36:10 +0200
At 13:12 Uhr +0100 29.07.2003, Chris Boot wrote:
I ended up using NSText's textDidChange: delegate method and and
NSMutableAttributesString's addAttributes:range: methods to do the
colouring, which works quite well except for the fact that it slows
to a crawl with any large quantity of text. I am already making
sure that I only colour things that the user could have changed, but
running an NSScanner or regular expression engine over 400K of text
takes a good few seconds. Any suggestions on speeding it up a bit?
I took a similar approach. Several speed-ups I've implemented (or am
planning to implement once I have time to spend on Workbench again)
are:
-> Do the recalc from a timer that is pushed forward while the user
is typing. This means that, as long as the user is typing, syntax
coloring doesn't happen, making it fast. As soon as the user has
stopped typing for a second or three, the timer fires and updates the
syntax coloring.
-> Add a second syntax coloring scheme that locally recolors. E.g.
only recolors the current line, starting at the location where the
user is currently writing, and then moving on to the left and right,
only recoloring more lines when necessary. To aid in that, you can
mark special ranges in the NSAttributedString with your own "style".
E.g. to turn off all syntax coloring if the user is currently inside
a comment, you'd just check whether the style at the insertion mark
is "MyMultiLineComment" or whatever.
BTW -- I'd be willing to share my code and collaborate on a more
generic syntax-coloring solution. This seems to come up a lot in
Cocoa applications.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.