Skip to content

Instantly share code, notes, and snippets.

@mikeabdullah
Created December 16, 2011 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeabdullah/1483787 to your computer and use it in GitHub Desktop.
Save mikeabdullah/1483787 to your computer and use it in GitHub Desktop.
Clearing undo manager's history while keeping document marked as edited
- (void)clearUndoHistoryOfDoc:(NSDocument *)doc
{
NSUndoManager *undoManager = [doc undoManager];
// Post a checkpoint first so any pending registrations
// (e.g. from Core Data) are committed
[[NSNotificationCenter defaultCenter]
postNotificationName:NSUndoManagerCheckpointNotification
object:undoManager];
// Now it's safe to clear the stack
[undoManager removeAllActions];
// Autosave-in-place sees the clearing of the undo stack as
// an indication that the doc is saved. Force it to see the
// doc as edited instead, with no way to undo the change
[doc updateChangeCount:NSChangeDone];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment