diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index cb850518ec..6051d01d0c 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -472,9 +472,7 @@ void LIB_EDIT_FRAME::SetCurPart( LIB_PART* aPart ) { m_toolManager->RunAction( EE_ACTIONS::clearSelection, true ); - if( m_my_part ) - delete m_my_part; - + delete m_my_part; m_my_part = aPart; // select the current component in the tree widget @@ -837,6 +835,21 @@ void LIB_EDIT_FRAME::RebuildView() void LIB_EDIT_FRAME::HardRedraw() { SyncLibraries( true ); + + if( m_my_part ) + { + EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool(); + EE_SELECTION& selection = selectionTool->GetSelection(); + + for( LIB_ITEM& item : m_my_part->GetDrawItems() ) + { + if( std::find( selection.begin(), selection.end(), &item ) == selection.end() ) + item.ClearSelected(); + else + item.SetSelected(); + } + } + RebuildView(); } diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index 0deb5a815a..f88ed33163 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -649,7 +649,6 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent ) if( !part ) return 0; - EE_SELECTION& selection = m_selectionTool->GetSelection(); std::string text = m_toolMgr->GetClipboard(); STRING_LINE_READER reader( text, "Clipboard" ); LIB_PART* newPart; @@ -674,6 +673,9 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent ) m_frame->SaveCopyInUndoList( part ); m_selectionTool->ClearSelection(); + for( LIB_ITEM& item : part->GetDrawItems() ) + item.ClearFlags( IS_NEW | IS_PASTED | SELECTED ); + for( LIB_ITEM& item : newPart->GetDrawItems() ) { if( item.Type() == LIB_FIELD_T ) @@ -694,6 +696,8 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent ) m_selectionTool->RebuildSelection(); + EE_SELECTION& selection = m_selectionTool->GetSelection(); + if( !selection.Empty() ) { selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) ); @@ -726,7 +730,7 @@ int LIB_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) { LIB_ITEM* oldItem = static_cast( selection.GetItem( ii ) ); LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone(); - oldItem->ClearFlags( SELECTED ); + oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED ); newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED ); newItem->SetParent( part ); newItems.push_back( newItem );