Re: NSTextStorage Problems - re-post
Re: NSTextStorage Problems - re-post
- Subject: Re: NSTextStorage Problems - re-post
- From: jerome LAURENS <email@hidden>
- Date: Thu, 27 Jun 2002 09:33:14 +0200
Le mardi 25 juin 2002, ` 06:20 PM, Josh Ferguson a icrit :
I posted this question last week, but didn't get a response, so I'm
hoping somebody who knows a lot about the text objects system will
notice this and have some pointers.
I'm creating a text editor that supports syntax coloring. To do this,
I've sub-classed NSTextStorage to store additional attributes. When I
open a blank document everything seems fine. When I type the first
character, my textView calls the various functions
(-fixAttributesInRange, -replaceCharactersInRange:withString...), but
the problem I have is in -attributesAtIndex:effectiveRange:. This
method gets called 4 times, with the first three times executing
succesfully (it's getting the attribute at index 0). The fourth time,
it tries to get the attribute for index 39, and since there is no index
39, it screws the whole system up. Just for kicks, I put a catch in to
just return if the index is greater than the length of the string, and
it just repeatedly calls attributesAtIndex, and effectively freezes the
application. Anyone have any ideas what could be going wrong here???
It seems that subclassing a NSTextStorage is very sensitive. It is not
really possible to give a straightforward answer because the problem is
highly complex (BTW why 39?).
However, here are some ideas:
- only subclass attributesAtIndex:effectiveRange: at start, you can
subclass others later for performance reasons
- in that methods, when a rangePtr is passed as argument, always return
a valid range, and never return a 0 length range, the same for effective
ranges.
_______________________________________________
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.