Re: Simple Undo Manager Problem
Re: Simple Undo Manager Problem
- Subject: Re: Simple Undo Manager Problem
- From: Martin Wierschin <email@hidden>
- Date: Wed, 25 Jul 2007 00:05:52 -0700
I added the following code before the filter takes place:
[[textArea undoManager] registerUndoWithTarget:textArea
selector:@selector(setString:) object:[textArea string]];
This successfully added an undo, but when I test it there is no
visable effect, and the textarea does not revert to the old text.
The problem is that the "string" method does not return an
independent NSString instance. The documentation for the method sums
this up:
"For performance reasons, this method returns the current backing
store of the text object. If you want to maintain a snapshot of this
as you manipulate the text storage, you should make a copy of the
appropriate substring"
So your undo code should look like:
NSString* snapshot = [[textArea string] copy];
[[textArea undoManager] registerUndoWithTarget:textArea
selector:@selector(setString:) object:snapshot];
[snapshot release];
~Martin
_______________________________________________
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