Browse Source

Fixes #2511. Cannot cycle selections in lists/tables when Numlock is pressed. (#2513)

* Fixes #2511. Cannot cycle selections in lists/tables when Numlock is pressed.

* The Capslock, Numlock and Scrolllock tests can be run once.

* Done requested changes.
BDisp 2 years ago
parent
commit
8ac9273493

+ 2 - 2
Terminal.Gui/Text/CollectionNavigator.cs

@@ -212,14 +212,14 @@ namespace Terminal.Gui {
 
 		/// <summary>
 		/// Returns true if <paramref name="kb"/> is a searchable key
-		/// (e.g. letters, numbers etc) that is valid to pass to to this
+		/// (e.g. letters, numbers, etc) that are valid to pass to this
 		/// class for search filtering.
 		/// </summary>
 		/// <param name="kb"></param>
 		/// <returns></returns>
 		public static bool IsCompatibleKey (KeyEvent kb)
 		{
-			return !kb.IsAlt && !kb.IsCapslock && !kb.IsCtrl && !kb.IsScrolllock && !kb.IsNumlock;
+			return !kb.IsAlt && !kb.IsCtrl;
 		}
 	}
 }

+ 28 - 0
UnitTests/Text/CollectionNavigatorTests.cs

@@ -376,5 +376,33 @@ namespace Terminal.Gui.TextTests {
 
 			Assert.Equal (-1, current = n.GetNextMatchingItem (current, "x", true));
 		}
+
+		[Fact]
+		public void IsCompatibleKey_Does_Not_Allow_Alt_And_Ctrl_Keys ()
+		{
+			// test all Keys
+			foreach (Key key in Enum.GetValues (typeof (Key))) {
+				var ke = new KeyEvent (key, new KeyModifiers () {
+					Alt = key == Key.AltMask,
+					Ctrl = key == Key.CtrlMask,
+					Shift = key == Key.ShiftMask
+				});
+				if (key == Key.AltMask || key == Key.CtrlMask) {
+					Assert.False (CollectionNavigator.IsCompatibleKey (ke));
+				} else {
+					Assert.True (CollectionNavigator.IsCompatibleKey (ke));
+				}
+			}
+
+			// test Capslock, Numlock and Scrolllock
+			Assert.True (CollectionNavigator.IsCompatibleKey (new KeyEvent (Key.Null, new KeyModifiers () {
+				Alt = false,
+				Ctrl = false,
+				Shift = false,
+				Capslock = true,
+				Numlock = true,
+				Scrolllock = true,
+			})));
+		}
 	}
 }