Skip to content

Instantly share code, notes, and snippets.

@MattyAyOh
Created January 4, 2016 18:33
Show Gist options
  • Save MattyAyOh/478df3a9cc160fcedcd2 to your computer and use it in GitHub Desktop.
Save MattyAyOh/478df3a9cc160fcedcd2 to your computer and use it in GitHub Desktop.
Remove empty undo group
id undostack = object_getIvar(undoManager, class_getInstanceVariable([NSUndoManager class], NEVER_TRANSLATE("_undoStack")));
id headAction = object_getIvar(undostack, class_getInstanceVariable([undostack class], NEVER_TRANSLATE("_head")));
id nextAction = object_getIvar(headAction, class_getInstanceVariable([headAction class], NEVER_TRANSLATE("next")));
const char *beginGroupName = NEVER_TRANSLATE("_NSUndoBeginMark");
const char *nextActionName = object_getClassName(nextAction);
if( strcmp(beginGroupName,nextActionName) == 0 )
{
[undoManager undo];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment