diff --git a/eeschema/widgets/search_handlers.cpp b/eeschema/widgets/search_handlers.cpp index 258a25f2ef..5b94fcf282 100644 --- a/eeschema/widgets/search_handlers.cpp +++ b/eeschema/widgets/search_handlers.cpp @@ -76,6 +76,8 @@ void SCH_SEARCH_HANDLER::SelectItems( std::vector& aItemRows ) EDA_ITEMS selectedItems; std::vector 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& 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 );