diff --git a/include/tool/selection.h b/include/tool/selection.h index 28e7d8d0e1..39e56fcd4f 100644 --- a/include/tool/selection.h +++ b/include/tool/selection.h @@ -168,6 +168,23 @@ public: return nullptr; } + /** + * Checks if there is at least one item of requested kind. + * + * @param aType is the type to check for. + * @return True if there is at least one item of such kind. + */ + bool HasType( KICAD_T aType ) const + { + for( auto item : m_items ) + { + if( item->Type() == aType ) + return true; + } + + return false; + } + virtual const VIEW_GROUP::ITEMS updateDrawList() const override; bool HasReferencePoint() const diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index a8fe42ba88..6278911fea 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -843,29 +843,26 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) if( m_selectionTool->CheckLock() == SELECTION_LOCKED ) return 0; - if( selection.Empty() ) - return 0; - // is this "alternative" remove? - const bool isAlt = aEvent.Parameter() == - (int) PCB_ACTIONS::REMOVE_FLAGS::ALT; + const bool isAlt = aEvent.Parameter() == (int) PCB_ACTIONS::REMOVE_FLAGS::ALT; - // in "alternative" mode, deletion is not just a simple list - // of selected items, it is: - // - whole tracks, not just segments - if( isAlt && selection.IsHover() ) + // in "alternative" mode, deletion is not just a simple list of selected items, + // it removes whole tracks, not just segments + if( isAlt && selection.IsHover() + && ( selection.HasType( PCB_TRACE_T ) || selection.HasType( PCB_VIA_T ) ) ) { m_toolMgr->RunAction( PCB_ACTIONS::selectConnection, true ); selection = m_selectionTool->RequestSelection( SELECTION_DELETABLE | SELECTION_SANITIZE_PADS ); } + if( selection.Empty() ) + return 0; + // As we are about to remove items, they have to be removed from the selection first m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); for( auto item : selection ) - { m_commit->Remove( item ); - } m_commit->Push( _( "Delete" ) );