Don't crash on empty selection in search list.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/14931
This commit is contained in:
Jeff Young 2023-06-12 23:07:04 +01:00
parent 782c73300b
commit 28075e6efe
1 changed files with 5 additions and 2 deletions

View File

@ -76,6 +76,8 @@ void SCH_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
EDA_ITEMS selectedItems;
std::vector<SCH_SEARCH_HIT> selectedHits;
m_frame->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true );
for( long row : aItemRows )
{
if( row >= 0 && row < (long) m_hitlist.size() )
@ -85,14 +87,15 @@ void SCH_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
}
}
if( selectedHits.empty() )
return;
bool allHitsOnSamePage = std::all_of( selectedHits.begin() + 1, selectedHits.end(),
[&]( const SCH_SEARCH_HIT& r )
{
return r.sheetPath == selectedHits.front().sheetPath;
} );
m_frame->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true );
if( allHitsOnSamePage && !selectedHits.empty() )
{
m_frame->SetCurrentSheet( *selectedHits.front().sheetPath );