From c816280c6d885fc95d85add36d3e781b2419c23b Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Wed, 24 Jan 2024 22:57:36 -0500 Subject: [PATCH] Move the current selection before deleting the row to avoid asserts Fixes sentry KICAD-63D --- eeschema/dialogs/dialog_lib_edit_pin_table.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index e49e44c4a9..d4190741f8 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -999,7 +999,6 @@ void DIALOG_LIB_EDIT_PIN_TABLE::AddPin( LIB_PIN* pin ) void DIALOG_LIB_EDIT_PIN_TABLE::OnDeleteRow( wxCommandEvent& event ) { // TODO: handle delete of multiple rows.... - if( !m_grid->CommitPendingChanges() ) return; @@ -1011,16 +1010,17 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnDeleteRow( wxCommandEvent& event ) if( curRow < 0 ) return; + // move the selection first because wx internally will try to reselect the row we deleted in out of order events + int nextSelRow = std::max( curRow-1, 0 ); + m_grid->GoToCell( nextSelRow, m_grid->GetGridCursorCol() ); + m_grid->SetGridCursor( nextSelRow, m_grid->GetGridCursorCol() ); + m_grid->SelectRow( nextSelRow ); + LIB_PINS removedRow = m_dataModel->RemoveRow( curRow ); for( LIB_PIN* pin : removedRow ) m_pins.erase( std::find( m_pins.begin(), m_pins.end(), pin ) ); - curRow = std::min( curRow, m_grid->GetNumberRows() - 1 ); - m_grid->GoToCell( curRow, m_grid->GetGridCursorCol() ); - m_grid->SetGridCursor( curRow, m_grid->GetGridCursorCol() ); - m_grid->SelectRow( curRow ); - updateSummary(); }