diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 583e8ab586..35d0649e98 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1201,22 +1201,35 @@ int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent ) { EE_SELECTION& selection = m_selectionTool->RequestSelection( rotatableItems ); + SCH_ITEM* head = static_cast( selection.Front() ); + bool moving = head && head->IsMoving(); if( selection.Empty() ) return 0; - SCH_ITEM* head = static_cast( selection.Front() ); - bool moving = head && head->IsMoving(); + std::vector autoplaceItems; for( unsigned ii = 0; ii < selection.GetSize(); ii++ ) { - SCH_ITEM* sch_item = static_cast( selection.GetItem( ii ) ); + SCH_ITEM* item = static_cast( selection.GetItem( ii ) ); + if( item->IsType( EE_COLLECTOR::FieldOwners ) ) + autoplaceItems.push_back( item ); + else if( item->GetParent() && item->GetParent()->IsType( EE_COLLECTOR::FieldOwners ) ) + autoplaceItems.push_back( static_cast( item->GetParent() ) ); + } + + bool appendUndo = false; + + for( SCH_ITEM* sch_item : autoplaceItems ) + { if( !moving && !sch_item->IsNew() ) - saveCopyInUndoList( sch_item, UNDO_REDO::CHANGED, ii > 0 ); + { + saveCopyInUndoList( sch_item, UNDO_REDO::CHANGED, appendUndo ); + appendUndo = true; + } - if( sch_item->IsType( EE_COLLECTOR::FieldOwners ) ) - sch_item->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true ); + sch_item->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true ); updateItem( sch_item, true ); }