NSUndoManager Won't Redo
NSUndoManager Won't Redo
- Subject: NSUndoManager Won't Redo
- From: Keary Suska <email@hidden>
- Date: Thu, 18 Jul 2013 12:58:48 -0600
Posting in hopes that someone has run into this case and figured it out.
Goal: I have a fairly vanilla document-based app whose content is made up of a number of discrete data bits, some managed by NSTextViews. I would like the text views to handle undo during editing as they should but without messing with the NSDocument's undo manager, if for no other reason than it causes the undo stack to get into an inconsistent state. Now, after the text view is exited, I want to register the undo as an all-or-nothing of the previous edits. Now, the docs seem to indicate that this is straightforward but my experience is showing otherwise.
Issue: once the text view is edited and the undo is registered, I can undo as expected, but if I choose redo nothing happens at all--i.e. the registered action doesn't occur. After that, the undo doesn't work either and the stacks seem to go inconsistent from that point.
Text view setup: has a delegate that provides an undo manager just for the text view, which is re-created every time the delegate gets a -textDidEndEditing: to make sure it is clean. I have verified that the undo manager the text view acquires is indeed different from NSDocument's.
- (void)textDidEndEditing:(NSNotification *)aNotification
{
// if we were editing, register undo
NSString *key = [[aNotification object] identifier];
id value = [_editingKeys objectForKey:key];
if (value)
{
[self.representedObject registerUndoForKey:key originalValue:value];
[_editingKeys removeObjectForKey:key];
// re-create so fresh each time
NSUndoManager *undoManager = [[NSUndoManager alloc] init];
self.undoManager = undoManager;
[undoManager release];
}
}
Catches/Caveats: text view attributed string is bound with continuously updates value (I want another part of the UI to update in real time). Setter does not register undo--that is done in registerUndoForKey:originalValue: shown above.
Note that undo works as expected *except* for putting the stacks in an inconsistent state as I mention at first.
Any clues?
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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