diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 53aa9011c6..1538f6d5d0 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -436,6 +436,8 @@ public: - (void)textDidChange:(NSNotification *)aNotification; - (void)changeColor:(id)sender; + @property (retain) NSUndoManager* undoManager; + @end @interface wxNSComboBox : NSComboBox diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index b52f1da4d7..3b8a92c671 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -426,6 +426,16 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; } } +- (instancetype)initWithFrame:(NSRect)frameRect +{ + self = [super initWithFrame:frameRect]; + if ( self ) + { + self.undoManager = [[[NSUndoManager alloc] init] autorelease]; + } + return self; +} + - (void)textDidChange:(NSNotification *)aNotification { wxUnusedVar(aNotification); @@ -434,6 +444,11 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; impl->controlTextDidChange(); } +- (nullable NSUndoManager *)undoManagerForTextView:(NSTextView *)view +{ + return self.undoManager; +} + - (void)changeColor:(id)sender { @@ -773,9 +788,7 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w, long s [tv setDelegate: tv]; - m_undoManager = nil; - if ( wxPeer && wxPeer->GetParent() && wxPeer->GetParent()->GetPeer() && wxPeer->GetParent()->GetPeer()->GetWXWidget() ) - m_undoManager = [wxPeer->GetParent()->GetPeer()->GetWXWidget() undoManager]; + m_undoManager = tv.undoManager; [tv setAllowsUndo:YES];