• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple Undo Manager Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Simple Undo Manager Problem (From: hac <email@hidden>)

  • Prev by Date: Re: C++ framework
  • Next by Date: Hierarchical defaults in NSUserDefaults?
  • Previous by thread: Simple Undo Manager Problem
  • Next by thread: Autorelease/Retain/Release
  • Index(es):
    • Date
    • Thread