Syntax Coloring...
Syntax Coloring...
- Subject: Syntax Coloring...
- From: "Josh Ferguson" <email@hidden>
- Date: Mon, 10 Jun 2002 10:28:53 -0500
- Thread-topic: Syntax Coloring...
Ok, this is probably a pretty basic question, but I've searched through the docs and haven't found an answer. I'm creating a basic text editor that supports syntax coloring (I know, novel idea...). In an effort to keep it running speedy (which is the reason I created it in the first place), I'm trying to keep the range of text that gets colored to a minimum. My problem is with "/**/" comments, as that's the only item that I'm coloring that will span multiple lines (otherwise I would just color one line at a time).
When the user types any input, I get the location for that input, then search backwards from that location for the nearest "/*", then just run my syntax coloring method from there. I then do a forward search for the first "*/" to determine where to end my coloring. This obviously isn't foolproof, as this doesn't take into consideration the fact that the text they're editing may not be a comment at all, and if the code has very few "/**/" comments, then the range being colored is going to be unnecessarily large. I determine what's being changed by using the textView:shouldChangeTextInRange:replacementString delegate method. If the user is deleting text, is there any way to check what character the user has deleted (that way I could just check to see if the user delete "/" and save myself a big headache)? If not, how do you get the range of text that's being displayed in the Scroll View (that way, I could just make sure that this text is always up to date).
I'm sorry if this seems stupid, I'm just kind of working from the ground up here, and I'm getting to the point where I think I need a fresh perspective. Feel free to criticize.
Josh Ferguson
_______________________________________________
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.