ADDED: Paste tabular contents to parent table.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21109
This commit is contained in:
Jeff Young 2025-07-31 14:14:25 +01:00
parent 6ac5ca7fc4
commit b0663d84cb
3 changed files with 46 additions and 10 deletions

View File

@ -714,7 +714,7 @@ void GRID_TRICKS::paste_clipboard()
// Some editors use windows linefeeds (\r\n), which wx re-writes to \n\n // Some editors use windows linefeeds (\r\n), which wx re-writes to \n\n
text.Replace( "\n\n", "\n" ); text.Replace( "\n\n", "\n" );
#endif #endif
m_grid->CommitPendingChanges( true );
paste_text( text ); paste_text( text );
} }

View File

@ -33,6 +33,7 @@
#include <wx/log.h> #include <wx/log.h>
#include <wx/settings.h> #include <wx/settings.h>
#include <confirm.h> #include <confirm.h>
#include <grid_tricks.h>
SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces, SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces,
bool aSingleLine, bool aSingleLine,
@ -216,6 +217,28 @@ void SCINTILLA_TRICKS::onModified( wxStyledTextEvent& aEvent )
void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent )
{ {
auto findGridTricks =
[&]() -> GRID_TRICKS*
{
wxWindow* parent = m_te->GetParent();
while( parent && !dynamic_cast<WX_GRID*>( parent ) )
parent = parent->GetParent();
if( WX_GRID* grid = dynamic_cast<WX_GRID*>( parent ) )
{
wxEvtHandler* handler = grid->GetEventHandler();
while( handler && !dynamic_cast<GRID_TRICKS*>( handler ) )
handler = handler->GetNextHandler();
if( GRID_TRICKS* gridTricks = dynamic_cast<GRID_TRICKS*>( handler ) )
return gridTricks;
}
return nullptr;
};
wxString c = aEvent.GetUnicodeKey(); wxString c = aEvent.GetUnicodeKey();
if( m_te->AutoCompActive() ) if( m_te->AutoCompActive() )
@ -373,7 +396,8 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent )
if( m_te->GetSelectionEnd() > m_te->GetSelectionStart() ) if( m_te->GetSelectionEnd() > m_te->GetSelectionStart() )
m_te->DeleteBack(); 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() ) if( wxTheClipboard->Open() )
{ {
@ -386,21 +410,30 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent )
wxTheClipboard->GetData( data ); wxTheClipboard->GetData( data );
str = data.GetText(); str = data.GetText();
ConvertSmartQuotesAndDashes( &str ); if( str.Contains( '\t' ) )
gridTricks = findGridTricks();
if( m_singleLine ) if( !gridTricks )
{ {
str.Replace( wxS( "\n" ), wxEmptyString ); ConvertSmartQuotesAndDashes( &str );
str.Replace( wxS( "\r" ), wxEmptyString );
}
m_te->BeginUndoAction(); if( m_singleLine )
m_te->AddText( str ); {
m_te->EndUndoAction(); str.Replace( wxS( "\n" ), wxEmptyString );
str.Replace( wxS( "\r" ), wxEmptyString );
}
m_te->BeginUndoAction();
m_te->AddText( str );
m_te->EndUndoAction();
}
} }
wxTheClipboard->Close(); wxTheClipboard->Close();
} }
if( gridTricks )
gridTricks->onKeyDown( aEvent );
} }
else if( aEvent.GetKeyCode() == WXK_BACK ) else if( aEvent.GetKeyCode() == WXK_BACK )
{ {

View File

@ -89,6 +89,9 @@ public:
} }
protected: protected:
/// Allow various conspiracies between the two tricks handlers
friend class SCINTILLA_TRICKS;
/// Shared initialization for various ctors. /// Shared initialization for various ctors.
void init(); void init();