Henry Rillovian Henry Rillovian - 9 months ago 60
Objective-C Question

Subclassing NSTextView makes undo impossible in Cocoa

I have a very simple Cocoa program. One window, with an NSTextView inside of it. In this configuration, the NSTextView operates exactly how you would expect it to. I can type, undo, redo, everything.

But then I subclass NSTextView, lets call it TextView. This new class does not override any methods, it's basically a blank subclass. I replace the NSTextView with my new subclass of it. I can type text into the TextView, but undo does not work. It just beeps at me. The undo menu item is greyed out. I would not expect this to happen, since TextView doesn't add any new code to the object inheritance structure.

What must I do to my TextView to re-enable undo?

GitHub project

XIB object hierarchy, "Text View" is my "TextView" class

Answer Source

overriding method : shouldChangeTextInRange cause this issue

i recommend you to check this link : Cocoa: looking for a general strategy for programmatic manipulation of NSTextView storage without messing up undo