From d67c81a65748d57daf3ae360293a1905b8d7f8f3 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 6 Sep 2022 18:11:56 +0300 Subject: [PATCH] When deselecting items, pick only selected ones. Fixes https://gitlab.com/kicad/code/kicad/issues/10292 --- eeschema/tools/ee_selection_tool.cpp | 10 ++++++++-- eeschema/tools/ee_selection_tool.h | 4 +++- pcbnew/tools/pcb_selection_tool.cpp | 10 ++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 226e33f85f..0ed06e70ac 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -818,7 +818,7 @@ bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& a void EE_SELECTION_TOOL::narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, - bool aCheckLocked ) + bool aCheckLocked, bool aSelectedOnly ) { for( int i = collector.GetCount() - 1; i >= 0; --i ) { @@ -833,6 +833,12 @@ void EE_SELECTION_TOOL::narrowSelection( EE_COLLECTOR& collector, const VECTOR2I collector.Remove( i ); continue; } + + if( aSelectedOnly && !collector[i]->IsSelected() ) + { + collector.Remove( i ); + continue; + } } // Apply some ugly heuristics to avoid disambiguation menus whenever possible @@ -947,7 +953,7 @@ bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, if( !CollectHits( collector, aWhere, aScanTypes ) ) return false; - narrowSelection( collector, aWhere, aCheckLocked ); + narrowSelection( collector, aWhere, aCheckLocked, aSubtract ); return selectPoint( collector, aWhere, aItem, aSelectionCancelledFlag, aAdd, aSubtract, aExclusiveOr ); diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index 66d072d9e6..9b3a4ec20a 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -191,8 +191,10 @@ private: * @param aCollector [in, out] Provides collection conditions and stores collected items. * @param aWhere point where we should narrow (if relevant) * @param aCheckLocked If false, remove locked elements from #collector + * @param aSelectedOnly If true, remove non-selected items from #collector */ - void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked ); + void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked, + bool aSelectedOnly = false ); /** * Perform a click-type selection at a point (usually the cursor position). diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 334d80dbcf..0e022044b6 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -722,6 +722,16 @@ bool PCB_SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag, // Apply the stateful filter FilterCollectedItems( collector, false ); + // For subtracting, we only want items that are selected + if( m_subtractive ) + { + for( int i = collector.GetCount() - 1; i >= 0; --i ) + { + if( !collector[i]->IsSelected() ) + collector.Remove( i ); + } + } + // Apply some ugly heuristics to avoid disambiguation menus whenever possible if( collector.GetCount() > 1 && !m_skip_heuristics ) GuessSelectionCandidates( collector, aWhere );