Skip to content

Commit

Permalink
Fixed minor issue: Cursor Key increment/decrement with Modifier key p…
Browse files Browse the repository at this point in the history
…ressed -> now modifiers can be used with cursor keys (eg SHIFT & Cursor right to select text)
  • Loading branch information
Dirkster99 committed Dec 14, 2020
1 parent a2cb8b1 commit e71db95
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions source/NumericUpDownLib/Base/AbstractBaseUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
return;
}

if (e.Key == Key.Up)
// support small value change via up cursor key
if (e.Key == Key.Up && IsModifierKeyDown() == false)
{
if (CanIncreaseCommand() == true)
IncreaseCommand.Execute(null, this);
Expand All @@ -822,29 +823,33 @@ private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
return;
}

if (e.Key == Key.Down)
// support small value change via down cursor key
if (e.Key == Key.Down && IsModifierKeyDown() == false)
{
if (CanDecreaseCommand() == true)
DecreaseCommand.Execute(null, this);

e.Handled = true;
return;
}
// support disable large change?
if (e.Key == Key.Right)

// support large value change via right cursor key
if (e.Key == Key.Right && IsModifierKeyDown() == false)
{
OnIncrement(LargeStepSize);
e.Handled = true;
return;
}

if (e.Key == Key.Left)
// support large value change via left cursor key
if (e.Key == Key.Left && IsModifierKeyDown() == false)
{
OnDecrement(LargeStepSize);
e.Handled = true;
return;
}

// update value typed by the user
if (e.Key == Key.Enter)
{
_PART_TextBox?.GetBindingExpression(TextBox.TextProperty).UpdateSource();
Expand All @@ -853,6 +858,17 @@ private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
}
}

/// <summary>
/// Gets whether any keyboard modifier (ALT, SHIFT, or CTRL) is down or not.
/// </summary>
/// <returns></returns>
private bool IsModifierKeyDown()
{
return Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) ||
Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl) ||
Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt);
}

/// <summary>
/// Checks if the current string entered in the textbox is:
/// 1) A valid number (syntax)
Expand Down

0 comments on commit e71db95

Please sign in to comment.