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: Sat, 15 Jan 2005 06:53:08 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Thanks again for the reply and the help.
I may (hopefully) have found a solution - it seems to
work with initial testing, but I'm nervous about
saying it definitely works after spending a week on
this with little luck. Sorry to include all this when
it's unlikely to be of direct interest to you, but
hopefully it might be of use to someone looking at the
archives in the future:
After playing around, as I understand it, the decision
about whether or not to begin a new undo group for
typing is made somewhere in NSTextView's
shouldChangeTextInRange:... I therefore created an
instance variable, BOOL _textViewUndo, and set this to
YES whenever the delegate's
textView:shouldChangeTextInRange:... method is
invoked. I set my delegate as an observer for undo
manager's NSUndoManagerDidOpenUndoGroupNotification.
Then, in the method called whenever the delegate
receives this notification, I check to see if
_textViewUndo is YES - if it is, I know that a new
undo group has been opened by the text view, and I add
all the undo invocations needed to reset my margin
card's associated character indices there, and then
reset _textViewUndo to NO.
This so far seems to work without breaking the text
view undo, as it just inserts these extra undos at the
beginning of the undo group, so that when undo is
called, the text gets reset and then the cards get
reset (I also have to make sure that the undo manager
is not undoing or redoing in textDidChange: before
making the amendments to the card indices there to
make sure that they don't clash with my undo method).
Thanks again for all the help, keep up the good work
with NWE!
All the best,
Keith
--- Martin <email@hidden> wrote:
> Keith,
>
> >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?
>
> Remember that an attribute has both a name and a
> value. The value can be anything you like, eg: a
> unique ID that you can map to a card.
>
> >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.
>
> This might be awkward to implement with attachment
> characters, since you'll run into the same problem
> as before. Namely that if you register an undo
> invocation while the user is typing it will break
> NSTextView's coalescing of keystrokes.
>
> This may or may not be a problem depending on
> when/where you relocate your card attachments.
> Perhaps the break in the undo group will appear to
> be quite natural to your users, since they will
> correspond to when the card attachment were deleted.
>
> >P.S. Your e-mail suggests you are from Nisus - if
> so,
> >I have to say, I love NWE 2!
>
> I am indeed from Nisus Software. I'm happy to hear
> that you enjoy our product! Working on it has
> definitely given me some experience with Apple's
> text system ;)
>
> ~Martin
>
>
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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