I created a simple demo app with a NSTextView and a button, the provided a NSTextViewDelegate to the textView and added an action:
- (IBAction)actionButtonClicke
-setString:
is an inherited method from NSText
. To handle this using NSTextView
methods only so that undo is handled, just do this:
[self.textView setSelectedRange:NSMakeRange(0, [[self.textView textStorage] length])];
[self.textView insertText:@"And… ACTION!"];
Making the text change this way avoids mucking about with the undo manager at all.