diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 00cb6e741c..0f3786c21f 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -374,6 +374,10 @@ void LIB_EDIT_FRAME::OnRemovePart( wxCommandEvent& aEvent ) if( isCurrentPart( libId ) ) emptyScreen(); + // Keeping a removed item selected may lead to a crash + if( m_treePane->GetCmpTree()->GetSelectedLibId( nullptr ) == libId ) + m_treePane->GetCmpTree()->SelectLibId( LIB_ID( libId.GetLibNickname(), "" ) ); + m_libMgr->RemovePart( libId.GetLibItemName(), libId.GetLibNickname() ); } @@ -395,6 +399,10 @@ void LIB_EDIT_FRAME::OnCopyCutPart( wxCommandEvent& aEvent ) if( isCurrentPart( libId ) ) emptyScreen(); + // Keeping a removed item selected may lead to a crash + if( m_treePane->GetCmpTree()->GetSelectedLibId( nullptr ) == libId ) + m_treePane->GetCmpTree()->SelectLibId( LIB_ID( libId.GetLibNickname(), "" ) ); + m_libMgr->RemovePart( libId.GetLibItemName(), libId.GetLibNickname() ); } }