diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index c9f73b5970..e9fe3d98d2 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -714,7 +714,7 @@ void GRID_TRICKS::paste_clipboard() // Some editors use windows linefeeds (\r\n), which wx re-writes to \n\n text.Replace( "\n\n", "\n" ); #endif - + m_grid->CommitPendingChanges( true ); paste_text( text ); } diff --git a/common/scintilla_tricks.cpp b/common/scintilla_tricks.cpp index 1449f9d58a..d1294bb1d9 100644 --- a/common/scintilla_tricks.cpp +++ b/common/scintilla_tricks.cpp @@ -33,6 +33,7 @@ #include #include #include +#include SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces, bool aSingleLine, @@ -216,6 +217,28 @@ void SCINTILLA_TRICKS::onModified( wxStyledTextEvent& aEvent ) void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) { + auto findGridTricks = + [&]() -> GRID_TRICKS* + { + wxWindow* parent = m_te->GetParent(); + + while( parent && !dynamic_cast( parent ) ) + parent = parent->GetParent(); + + if( WX_GRID* grid = dynamic_cast( parent ) ) + { + wxEvtHandler* handler = grid->GetEventHandler(); + + while( handler && !dynamic_cast( handler ) ) + handler = handler->GetNextHandler(); + + if( GRID_TRICKS* gridTricks = dynamic_cast( handler ) ) + return gridTricks; + } + + return nullptr; + }; + wxString c = aEvent.GetUnicodeKey(); if( m_te->AutoCompActive() ) @@ -373,7 +396,8 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) if( m_te->GetSelectionEnd() > m_te->GetSelectionStart() ) m_te->DeleteBack(); - wxLogNull doNotLog; // disable logging of failed clipboard actions + GRID_TRICKS* gridTricks = nullptr; + wxLogNull doNotLog; // disable logging of failed clipboard actions if( wxTheClipboard->Open() ) { @@ -386,21 +410,30 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) wxTheClipboard->GetData( data ); str = data.GetText(); - ConvertSmartQuotesAndDashes( &str ); + if( str.Contains( '\t' ) ) + gridTricks = findGridTricks(); - if( m_singleLine ) + if( !gridTricks ) { - str.Replace( wxS( "\n" ), wxEmptyString ); - str.Replace( wxS( "\r" ), wxEmptyString ); - } + ConvertSmartQuotesAndDashes( &str ); - m_te->BeginUndoAction(); - m_te->AddText( str ); - m_te->EndUndoAction(); + if( m_singleLine ) + { + str.Replace( wxS( "\n" ), wxEmptyString ); + str.Replace( wxS( "\r" ), wxEmptyString ); + } + + m_te->BeginUndoAction(); + m_te->AddText( str ); + m_te->EndUndoAction(); + } } wxTheClipboard->Close(); } + + if( gridTricks ) + gridTricks->onKeyDown( aEvent ); } else if( aEvent.GetKeyCode() == WXK_BACK ) { diff --git a/include/grid_tricks.h b/include/grid_tricks.h index f14d826ccc..5d9c813cbd 100644 --- a/include/grid_tricks.h +++ b/include/grid_tricks.h @@ -89,6 +89,9 @@ public: } protected: + /// Allow various conspiracies between the two tricks handlers + friend class SCINTILLA_TRICKS; + /// Shared initialization for various ctors. void init();