diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index 08bb0752c0..3096408445 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -113,7 +113,7 @@ int COMMON_TOOLS::CursorControl( const TOOL_EVENT& aEvent ) wxFAIL_MSG( "CursorControl(): unexpected request" ); } - getViewControls()->SetCursorPosition( cursor, true, true ); + getViewControls()->SetCursorPosition( cursor, true, true, type ); m_toolMgr->RunAction( ACTIONS::refreshPreview ); return 0; diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 4d6fb72e85..214f53aefb 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -487,7 +487,7 @@ VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition( bool aEnableSnapping ) const void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView, - bool aTriggeredByArrows ) + bool aTriggeredByArrows, long aArrowCommand ) { m_updateCursor = false; @@ -495,6 +495,7 @@ void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpV { m_settings.m_lastKeyboardCursorPositionValid = true; m_settings.m_lastKeyboardCursorPosition = aPosition; + m_settings.m_lastKeyboardCursorCommand = aArrowCommand; m_cursorWarped = false; } else diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 4f9f4f6db8..2844b99c90 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -96,6 +96,9 @@ struct VC_SETTINGS ///> Is last cursor motion event coming from keyboard arrow cursor motion action bool m_lastKeyboardCursorPositionValid; + ///> ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc. + long m_lastKeyboardCursorCommand; + ///> Position of the above event VECTOR2D m_lastKeyboardCursorPosition; }; @@ -248,7 +251,8 @@ public: * @param aPosition is the requested cursor position in the world coordinates. * @param aWarpView enables/disables view warp if the cursor is outside the current viewport. */ - virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true, bool aTriggeredByArrows = false ) = 0; + virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true, + bool aTriggeredByArrows = false, long aArrowCommand = 0 ) = 0; /** diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index f94182d9fb..f3b9a112d4 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -85,7 +85,8 @@ public: /// @copydoc VIEW_CONTROLS::GetRawCursorPosition() VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override; - void SetCursorPosition( const VECTOR2D& aPosition, bool warpView, bool aTriggeredByArrows ) override; + void SetCursorPosition( const VECTOR2D& aPosition, bool warpView, + bool aTriggeredByArrows, long aArrowCommand ) override; /// @copydoc VIEW_CONTROLS::SetCrossHairCursorPosition() void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 2660d97727..5ea8f891cc 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -323,7 +323,21 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) if( m_dragging && evt->Category() == TC_MOUSE ) { VECTOR2I mousePos( controls->GetMousePosition() ); + m_cursor = grid.BestSnapAnchor( mousePos, item_layers, sel_items ); + + if( controls->GetSettings().m_lastKeyboardCursorPositionValid ) + { + long action = controls->GetSettings().m_lastKeyboardCursorCommand; + + // The arrow keys are by definition SINGLE AXIS. Do not allow the other + // axis to be snapped to the grid. + if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT ) + m_cursor.y = prevPos.y; + else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN ) + m_cursor.x = prevPos.x; + } + controls->ForceCursorPosition( true, m_cursor ); selection.SetReferencePoint( m_cursor );