From 4fcd18e6ea7e80b45eeda80fe0bddf2c2a9e06b0 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Thu, 19 Aug 2021 19:56:03 +0200 Subject: [PATCH] Use a private undo manager for wxTextCtrl This allows each control have its own undo history, independent of the other ones, as expected by the wx API, rather than using an undo manager shared by all controls in the same TLW. --- include/wx/osx/cocoa/private.h | 2 ++ src/osx/cocoa/textctrl.mm | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) 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];