Re: Syntax Colouring
Re: Syntax Colouring
- Subject: Re: Syntax Colouring
- From: Glenn Andreas <email@hidden>
- Date: Tue, 29 Jul 2003 10:02:09 -0500
At 1:12 PM +0100 7/29/03, 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?
Thanks in advance.
I had this same problem, and ended up writing my own finite-state
machine to lexically analyze the text, which is usually good enough
for syntax coloring. In a perfect world you'd also include the
current state as a custom attribute so that when something is
editted, you can just go backwards from the point of the edit to some
place where the state was the default/start state, and color from
there (for example, if you have comments in /*...*/ you might not
color that until you typed the closing "*/", at which point you'd
have to close everything from the openning "/*" forward). If what
you are coloring is simple enough, though, you can probably just
extend the selection given to textDidChange: to the entire line.
BTW, I use textStorageDidProcessEditing as the point of doing the
syntax coloring, so I don't see any problems that you saw with
textStorageWillProcessEditing (I believe I originally used this).
Glenn Andreas email@hidden
Author of Macintosh games: Theldrow 2.3, Blobbo 1.0.2, Cythera 1.0.2
Be good, and you will be lonesome
_______________________________________________
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.