Re: Maintaining an ordered array of attributes in an NSTextStorage subclass
Re: Maintaining an ordered array of attributes in an NSTextStorage subclass
- Subject: Re: Maintaining an ordered array of attributes in an NSTextStorage subclass
- From: Graham Cox <email@hidden>
- Date: Mon, 10 Aug 2009 23:43:01 +1000
On 10/08/2009, at 11:21 PM, Keith Blount wrote:
Thanks for the reply. I guess I lost the point in my long, rambling
e-mail, so sorry about that. What I really meant to ask is *how* to
maintain this list accurately. Given that the attribute can be
added, removed, text can be copied and pasted, a range of text that
has a comment associated with it might be cut in half and so on,
what is the best approach for keeping this list updated as the text
changes?
Ah, my bad - I guess the clue was in your message title ;-)
In theory, code is supposed to call beginEdiing/endEditing around any
operation that edits the text so that might be one place you could
override to handle this. Other methods in NSMutableAttributedString
may need to be overridden to get information about affected ranges.
There are only two primitive methods, according to the docs:
- (void)replaceCharactersInRange:(NSRange)aRange withString:(NSString
*)aString
- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)aRange
So those two should provide all the hooks you'd need. If your
auxiliary array is kept sorted by range position it should be easy and
efficient to locate the relevant entries affected by an edit in a
given range. Ideally you'd want to manage the comments such that the
text storage does all the hard work of maintaining the attribute runs/
ranges, and all you have to do is to add and delete comments in your
array as necessary.
Still a bit vague, but might help with the inspiration...
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden