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: Keith Blount <email@hidden>
- Date: Fri, 14 Jan 2005 10:34:49 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello, and many thanks for your reply, much
appreciated.
Your attributes suggestion would be nice and simple,
but the trouble is, how would each card know which
piece of text with that attribute that it was attached
to?
I did consider the attachment route, but the main
problems I thought I would have were, 1) I thought
attachments had to be associated with files in file
wrappers (I am probably completely wrong), but mainly,
2) it wouldn't solve the problem of having to adjust
placements in textDidChange:. The way I have it
working is that if the user types, the card changes
the position if the affected character index is
affected - and for that it would probably be much
simpler to use a text attachment as you suggest. But
if the character is deleted, I don't want the margin
card deleted - instead, it should now be attached to
the character at the end of the attachment range.
Thinking about it, if I can get the latter part
working with text attachments by checking for them in
textDidChange and calling textViewShouldChange... etc
on the amendments to make sure they get registered
with undo, then your suggestion may be the way to go.
I will experiment this weekend.
Many thanks again for your help,
Keith
P.S. Your e-mail suggests you are from Nisus - if so,
I have to say, I love NWE 2!
--- Martin <email@hidden> wrote:
>
> 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 you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
_______________________________________________
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