Remove selection before notifying grid of deletion.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20747

(cherry picked from commit a1cc6403bd)
This commit is contained in:
Jeff Young
2025-05-31 11:03:59 +01:00
parent 0ff77bd332
commit ee62366607
7 changed files with 13 additions and 5 deletions
+1 -1
View File
@@ -797,7 +797,7 @@ void DIALOG_LABEL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
for( int row : selectedRows )
{
//avoids an assert if we deselect early here
m_grid->DeselectRow( row );
m_grid->ClearSelection();
m_fields->erase( m_fields->begin() + row );
// notify the grid
@@ -633,13 +633,13 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
}
m_grid->CommitPendingChanges( true /* quiet mode */ );
m_grid->ClearSelection();
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
for( int row : selectedRows )
{
m_grid->ClearSelection();
m_fields->erase( m_fields->begin() + row );
// notify the grid
@@ -714,6 +714,8 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event )
if( !m_grid->CommitPendingChanges() )
return;
m_grid->ClearSelection();
std::vector<SCH_FIELD> fields;
for( const SCH_FIELD& field : *m_fields )
@@ -798,6 +798,7 @@ void DIALOG_SHEET_PROPERTIES::OnDeleteField( wxCommandEvent& event )
for( int row : selectedRows )
{
m_grid->ClearSelection();
m_fields->erase( m_fields->begin() + row );
// notify the grid
@@ -558,6 +558,8 @@ void DIALOG_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event )
if( !m_fieldsGrid->CommitPendingChanges() )
return;
m_fieldsGrid->ClearSelection();
std::vector<SCH_FIELD> fields;
for( const SCH_FIELD& field : *m_fields )
@@ -887,13 +889,13 @@ void DIALOG_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
}
m_fieldsGrid->CommitPendingChanges( true /* quiet mode */ );
m_fieldsGrid->ClearSelection();
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
for( int row : selectedRows )
{
m_fieldsGrid->ClearSelection();
m_fields->erase( m_fields->begin() + row );
// notify the grid
+2
View File
@@ -190,11 +190,13 @@ public:
{
LIB_TABLE_ROWS_ITER start = begin() + aPos;
erase( start, start + aNumRows );
if( GetView() )
{
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPos, aNumRows );
GetView()->ProcessTableMessage( msg );
}
return true;
}
@@ -724,13 +724,13 @@ void DIALOG_FOOTPRINT_PROPERTIES::OnDeleteField( wxCommandEvent& )
}
m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
m_itemsGrid->ClearSelection();
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
for( int row : selectedRows )
{
m_itemsGrid->ClearSelection();
m_fields->erase( m_fields->begin() + row );
// notify the grid
@@ -752,7 +752,6 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnDeleteField( wxCommandEvent& event
}
m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
m_itemsGrid->ClearSelection();
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
selectedRows.Sort( []( int* first, int* second )
@@ -762,6 +761,7 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnDeleteField( wxCommandEvent& event
for( int row : selectedRows )
{
m_itemsGrid->ClearSelection();
m_fields->erase( m_fields->begin() + row );
// notify the grid
@@ -813,6 +813,7 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnDeleteLayer( wxCommandEvent& event
if( curRow < 0 )
return;
m_privateLayersGrid->ClearSelection();
m_privateLayers->erase( m_privateLayers->begin() + curRow );
// notify the grid