Re: Adding an undo method in textView:shouldChangeTextInRange:...
Re: Adding an undo method in textView:shouldChangeTextInRange:...
- Subject: Re: Adding an undo method in textView:shouldChangeTextInRange:...
- From: "Martin" <email@hidden>
- Date: Thu, 13 Jan 2005 18:26:40 -0800
On January 13 2005, Keith Blount <email@hidden> wrote:
>I have a custom view that does various things (mainly
>move little note cards around) whenever an associated
>text view's text is updated.
..
>I am now trying to implement undo,
>and when it comes to trying to undo the changes in my
>custom view that were made in these methods, I am
>hitting my head against a brick wall.
Hi Keith,
I believe NSTextView and NSUndoManager use some private methods to coalesce typing so that each individual character insertion is not a separate undo invocation. I do not think there is an obvious way to extend this behavior to include your own custom undo invocations. And even if there were, I might recommend a different approach anyways.
Rather than tracking/storing the character indexes of your note cards separate from the provided text machinery (NSTextStorage, NSTextView, etc), why not let them do the work for you? Some options:
1. Use a custom NSTextAttachment subclass to represent each note card inline.
2. Create a custom attribute name/value pair to let you know that a note card is applied to a range of text.
3. Create a custom subclass of NSTextStorage that stores these note card character indexes. Just override "-replaceCharactersInRange:withString:" to do the right thing for your notes. Since you'll need to keep track of deleted note cards in the undo stack, the text storage will need access to the document's undo manager somehow.
All these options (especially 1 and 2) let you make use of all the existing code Apple has written to keep track of edits.
~Martin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden