From 08a932a969ed17e3352e376cc2fff5b5e934645b Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 31 Jan 2021 06:59:18 -0800 Subject: [PATCH] Add smarts to switch selection on right-click Now looks at how hard it is to select the item (grids) and switches only if the mouse is more than a grid square away and there is a new item under the mouse. Fixes https://gitlab.com/kicad/code/kicad/issues/4455 --- eeschema/tools/ee_selection_tool.cpp | 32 ++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 90137d9791..05df061153 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -392,14 +392,42 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // right click? if there is any object - show the context menu bool selectionCancelled = false; - if( m_selection.Empty() || - !m_selection.GetBoundingBox().Contains( (wxPoint) evt->Position() ) ) + if( m_selection.Empty() ) { ClearSelection(); SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr, &selectionCancelled ); m_selection.SetIsHover( true ); } + // If the cursor has moved off the bounding box of the selection by more than + // a grid square, check to see if there is another item available for selection + // under the cursor. If there is, the user likely meant to get the context menu + // for that item. If there is no new item, then keep the original selection and + // show the context menu for it. + else if( !m_selection.GetBoundingBox().Inflate( + grid.GetGrid().x, grid.GetGrid().y ).Contains( + (wxPoint) evt->Position() ) ) + { + EE_SELECTION saved_selection = m_selection; + + for( auto item : m_selection ) + RemoveItemFromSel( item, true ); + + SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr, + &selectionCancelled ); + + if( m_selection.Empty() ) + { + m_selection.SetIsHover( false ); + + for( auto item : saved_selection ) + AddItemToSel( item, true); + } + else + { + m_selection.SetIsHover( true ); + } + } if( !selectionCancelled ) m_menu.ShowContextMenu( m_selection );