Re: Syntax Coloring...
Re: Syntax Coloring...
- Subject: Re: Syntax Coloring...
- From: Thomas Deniau <email@hidden>
- Date: Mon, 10 Jun 2002 19:37:41 +0200
Le 10/06/02 17:28, Josh Ferguson disait :
>
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...).
Try to subclass the text storage and override
- (void) fixAttributesInRange: (NSRange) aRange;
and
- (void)replaceCharactersInRange:(NSRange)aRange withString:(NSString
*)aString
This way you can keep track of the 'status' of a range of text (is a
comment, is an idented comment, ...) using your own attributes in the text
storage's attributed string, and then 'convert' to attributes such as font,
identation, etc., in
- (NSDictionary *) attributesAtIndex: (unsigned) aLocation effectiveRange:
(NSRangePointer) aRangePtr;
For example in fixAttributesInRange you add your own attributes to the
attributed string, like TextIdentation = x, TextType = Comment, which allows
you to keep track of the structure of your doc, etc. and in
attributesAtIndex: you return a green color if the value of TextType ==
Comment.
And using your 'structure' tags you can minimize the range which needs to be
invalidated.
HTH
PS : I've some sample code available if you need it (GPL)
--
Thomas Deniau
_______________________________________________
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.