Fix bugs in keyboard cursor movement.

1) Generate refreshPreview events so the modern toolset doesn't
fall behind by one event (see LP:1818667)
2) In the legacy toolset don't call unimplemented routines and don't
snap to grid on the non-movement axis.
This commit is contained in:
Jeff Young 2019-07-05 01:32:15 +01:00
parent ecadc8bbba
commit 85220591e2
6 changed files with 23 additions and 15 deletions

View File

@ -1294,56 +1294,56 @@ bool EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
* sub-pixel movement. The m_movingCursorWithKeyboard oneshot 'eats'
* the automatic motion event generated by cursor warping */
wxRealPoint gridSize = GetScreen()->GetGridSize();
*aPos = GetCrossHairPosition();
*aPos = (wxPoint) m_galCanvas->GetViewControls()->GetRawCursorPosition( false );
// Bonus: ^key moves faster (x10)
switch( aHotKey )
{
case GR_KB_CTRL|WXK_NUMPAD8:
case GR_KB_CTRL|WXK_UP:
aPos->y -= KiROUND( 10 * gridSize.y );
aPos->y = GetNearestGridPosition( *aPos ).y - KiROUND( 10 * gridSize.y );
break;
case GR_KB_CTRL|WXK_NUMPAD2:
case GR_KB_CTRL|WXK_DOWN:
aPos->y += KiROUND( 10 * gridSize.y );
aPos->y = GetNearestGridPosition( *aPos ).y + KiROUND( 10 * gridSize.y );
break;
case GR_KB_CTRL|WXK_NUMPAD4:
case GR_KB_CTRL|WXK_LEFT:
aPos->x -= KiROUND( 10 * gridSize.x );
aPos->x = GetNearestGridPosition( *aPos ).x - KiROUND( 10 * gridSize.x );
break;
case GR_KB_CTRL|WXK_NUMPAD6:
case GR_KB_CTRL|WXK_RIGHT:
aPos->x += KiROUND( 10 * gridSize.x );
aPos->x = GetNearestGridPosition( *aPos ).x + KiROUND( 10 * gridSize.x );
break;
case WXK_NUMPAD8:
case WXK_UP:
aPos->y -= KiROUND( gridSize.y );
aPos->y = GetNearestGridPosition( *aPos ).y - KiROUND( gridSize.y );
break;
case WXK_NUMPAD2:
case WXK_DOWN:
aPos->y += KiROUND( gridSize.y );
aPos->y = GetNearestGridPosition( *aPos ).y + KiROUND( gridSize.y );
break;
case WXK_NUMPAD4:
case WXK_LEFT:
aPos->x -= KiROUND( gridSize.x );
aPos->x = GetNearestGridPosition( *aPos ).x - KiROUND( gridSize.x );
break;
case WXK_NUMPAD6:
case WXK_RIGHT:
aPos->x += KiROUND( gridSize.x );
aPos->x = GetNearestGridPosition( *aPos ).x + KiROUND( gridSize.x );
break;
default: /* Can't happen since we entered the statement */
break;
}
m_canvas->MoveCursor( *aPos );
m_galCanvas->GetViewControls()->SetCursorPosition( *aPos, true, true );
m_movingCursorWithKeyboard = true;
}
break;

View File

@ -90,6 +90,8 @@ TOOL_ACTION ACTIONS::cursorDblClick( "common.Control.cursorDblClick",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LEFT_DCLICK ),
"", "", NULL, AF_NONE, (void*) CURSOR_DBL_CLICK );
TOOL_ACTION ACTIONS::refreshPreview( "common.Control.refreshPreview",
AS_GLOBAL );
TOOL_ACTION ACTIONS::panUp( "common.Control.panUp",
AS_GLOBAL, MD_SHIFT + WXK_UP,

View File

@ -117,6 +117,7 @@ int COMMON_TOOLS::CursorControl( const TOOL_EVENT& aEvent )
}
getViewControls()->SetCursorPosition( cursor, true, true );
m_toolMgr->RunAction( ACTIONS::refreshPreview );
return 0;
}

View File

@ -281,11 +281,11 @@ bool SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE
if( aHotKey )
{
if( m_movingCursorWithKeyboard ) // The hotkey was a move crossahir cursor command
if( m_movingCursorWithKeyboard )
{
// The crossair was moved. move the mouse cursor to the new crosshair position:
GetGalCanvas()->GetViewControls()->WarpCursor( GetCrossHairPosition(), true );
m_movingCursorWithKeyboard = 0;
// The hotkey was a move crosshair cursor command. We've already done the work;
// just eat the event and reset the flag.
m_movingCursorWithKeyboard = false;
}
else
{

View File

@ -58,6 +58,9 @@ public:
static TOOL_ACTION zoomTool;
static TOOL_ACTION centerContents;
static TOOL_ACTION refreshPreview; // Similar to a synthetic mouseMoved event, but also
// used after a rotate, mirror, etc.
/// Cursor control with keyboard
static TOOL_ACTION cursorUp;
static TOOL_ACTION cursorDown;

View File

@ -414,7 +414,9 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
if( evt->IsAction( &PCB_ACTIONS::editActivate ) ||
evt->IsAction( &PCB_ACTIONS::move ) ||
evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
evt->IsMotion() ||
evt->IsDrag( BUT_LEFT ) ||
evt->IsAction( &ACTIONS::refreshPreview ) )
{
if( m_dragging && evt->Category() == TC_MOUSE )
{