Skip to content

Commit e71db95

Browse files
committed
Fixed minor issue: Cursor Key increment/decrement with Modifier key pressed -> now modifiers can be used with cursor keys (eg SHIFT & Cursor right to select text)
1 parent a2cb8b1 commit e71db95

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

source/NumericUpDownLib/Base/AbstractBaseUpDown.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,8 @@ private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
813813
return;
814814
}
815815

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

825-
if (e.Key == Key.Down)
826+
// support small value change via down cursor key
827+
if (e.Key == Key.Down && IsModifierKeyDown() == false)
826828
{
827829
if (CanDecreaseCommand() == true)
828830
DecreaseCommand.Execute(null, this);
829831

830832
e.Handled = true;
831833
return;
832834
}
833-
// support disable large change?
834-
if (e.Key == Key.Right)
835+
836+
// support large value change via right cursor key
837+
if (e.Key == Key.Right && IsModifierKeyDown() == false)
835838
{
836839
OnIncrement(LargeStepSize);
837840
e.Handled = true;
838841
return;
839842
}
840843

841-
if (e.Key == Key.Left)
844+
// support large value change via left cursor key
845+
if (e.Key == Key.Left && IsModifierKeyDown() == false)
842846
{
843847
OnDecrement(LargeStepSize);
844848
e.Handled = true;
845849
return;
846850
}
847851

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

861+
/// <summary>
862+
/// Gets whether any keyboard modifier (ALT, SHIFT, or CTRL) is down or not.
863+
/// </summary>
864+
/// <returns></returns>
865+
private bool IsModifierKeyDown()
866+
{
867+
return Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) ||
868+
Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl) ||
869+
Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt);
870+
}
871+
856872
/// <summary>
857873
/// Checks if the current string entered in the textbox is:
858874
/// 1) A valid number (syntax)

0 commit comments

Comments
 (0)