Search code examples
objective-cuitextviewnsundomanager

UITextView and NSUndoManager synchronisation


I have tried to search first but couldn't find exactly what I need.

I have one UITextView and I have buttons that are executing actions undo and redo on UITextViews NSUndoManager so that part is working but here comes the problem. Undo actions are undoing all changes that I create after text view becomes first responder, so to be able to have detailed undo or redo actions that are undoing or redoing only the last action and not all actions performed from the moment where UITextView become first responder I should have code like this:

- (void)textViewDidChange:(UITextView *)textView
{
    [textView resignFirstResponder];
    [textView becomeFirstResponder];
}

But this code is not a solution, it works but I would like to synchronize actions performed in UITextView in the same way like the code above but without resigning UITextView as the first responder.

Tnx for help.


Solution

  • If im not wrong, each undo/redo action is grouped by an event loop. If yo do many thing within the same event loop, all those things form the same action.