diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 8f4337ad0e..308ad8c703 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -340,15 +340,32 @@ SCH_ITEM* SCH_EDITOR_CONTROL::nextMatch( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aS if( aAfter != nullptr ) { past_item = false; - - if( aAfter->Type() == SCH_PIN_T || aAfter->Type() == SCH_FIELD_T ) - aAfter = static_cast( aAfter->GetParent() ); } std::vector sorted_items; for( SCH_ITEM* item : aScreen->Items() ) + { + if( SCH_SYMBOL* sym = dyn_cast( item ) ) + { + for( SCH_FIELD& field : sym->GetFields() ) + sorted_items.push_back( &field ); + + for( SCH_PIN* pin : sym->GetPins() ) + sorted_items.push_back( pin ); + } + + if( SCH_SHEET* sheet = dyn_cast( item ) ) + { + for( SCH_FIELD& field : sheet->GetFields() ) + sorted_items.push_back( &field ); + + for( SCH_SHEET_PIN* pin : sheet->GetPins() ) + sorted_items.push_back( pin ); + } + sorted_items.push_back( item ); + } std::sort( sorted_items.begin(), sorted_items.end(), [&]( SCH_ITEM* a, SCH_ITEM* b ) @@ -379,40 +396,6 @@ SCH_ITEM* SCH_EDITOR_CONTROL::nextMatch( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aS if( item->Matches( aData, aSheet ) ) return item; - - if( item->Type() == SCH_SYMBOL_T ) - { - SCH_SYMBOL* cmp = static_cast( item ); - - for( SCH_FIELD& field : cmp->GetFields() ) - { - if( field.Matches( aData, aSheet ) ) - return &field; - } - - for( SCH_PIN* pin : cmp->GetPins() ) - { - if( pin->Matches( aData, aSheet ) ) - return pin; - } - } - - if( item->Type() == SCH_SHEET_T ) - { - SCH_SHEET* sheet = static_cast( item ); - - for( SCH_FIELD& field : sheet->GetFields() ) - { - if( field.Matches( aData, aSheet ) ) - return &field; - } - - for( SCH_SHEET_PIN* pin : sheet->GetPins() ) - { - if( pin->Matches( aData, aSheet ) ) - return pin; - } - } } }