According to documentation it's enough to override NSResponder.undoManager
to provide custom NSUndoManager
instance. I found it's not quite working:
- Xcode Mac application template comes with Undo menu item bind to
firstResponder.undo:
despiteNSResponder
has noundo:
selector defined. Unless first responder actually respond toundo:
the Undo action doesn't work - NSFirstResponder.undoManager look up in responder chain and eventually it end up in NSWindow where the only place (that I found) that validate Undo menu item is
NSWindow.validateUserInterfaceItem
- that one, as turned out, only ever validateundo:
action if first responder implements_getUndoManager:
selector (quite private, isn't it?) - see attached disassembly
at this point 🤕 I start to think it's either documentation issue, or AppKit implementation issue. Anyway, I didn't found way to enable undo:
action unless I implement one of these methods in my NSView
. (notice: the view is first responder that I confirmed). Or I'm doing it wrong, and does it ever custom undoManager for custom NSView/NSControl ever worked.
In AppKit, the only implementations of undo: in appkit are on NSWindow which calls that _getActiveUndoManager
method. The overriden NSResponder.undoManager
is never called.
What I'm trying to achieve here is provide custom NSUndoManager
subclass for my NSView
(first responder)
For the reference GnuSTEP has it right: https://github.com/gnustep/libs-gui/blob/efb9bcb2e7c4bde76932702dd40358090831507c/Source/NSWindow.m#L5574
Based on Slack discussion with peers, it seems to be an old REGRESSION introduced ~10 or 20 years ago ¯_(ツ)_/¯