2
0
Эх сурвалжийг харах

fixed (for real?) unit test that proves 'wrong' key behavior is broken

Charlie Kindel 2 жил өмнө
parent
commit
2200dc0964

+ 8 - 0
Terminal.Gui/Core/CollectionNavigator.cs

@@ -135,6 +135,14 @@ namespace Terminal.Gui {
 				lastKeystroke = DateTime.Now;
 				idxCandidate = GetNextMatchingItem (currentIndex, candidateState);
 
+				//// if a match wasn't found, the user typed a 'wrong' key in their search ("can" + 'z'
+				//// instead of "can" + 'd').
+				//if (SearchString.Length > 1 && idxCandidate == -1) {
+				//	// ignore it since we're still within the typing delay
+				//	// don't add it to SearchString either
+				//	return currentIndex;
+				//}
+
 				// if no changes to current state manifested
 				if (idxCandidate == currentIndex || idxCandidate == -1) {
 					// clear history and treat as a fresh letter

+ 3 - 0
UnitTests/CollectionNavigatorTests.cs

@@ -282,6 +282,7 @@ namespace Terminal.Gui.Core {
 			// This would only apply for 2+ character searches where theres been a successful 2+ character match right before.
 
 			Assert.Equal (strings.IndexOf ("a"), current = n.GetNextMatchingItem (current, 'a'));
+			Assert.Equal ("a", n.SearchString);
 			Assert.Equal (strings.IndexOf ("c"), current = n.GetNextMatchingItem (current, 'c'));
 			Assert.Equal ("c", n.SearchString);
 			Assert.Equal (strings.IndexOf ("can"), current = n.GetNextMatchingItem (current, 'a'));
@@ -292,7 +293,9 @@ namespace Terminal.Gui.Core {
 			Assert.Equal ("cand", n.SearchString);
 
 			// Same as above, but with a 'wrong' key (z)
+			Thread.Sleep (n.TypingDelay + 10);
 			Assert.Equal (strings.IndexOf ("a"), current = n.GetNextMatchingItem (current, 'a'));
+			Assert.Equal ("a", n.SearchString);
 			Assert.Equal (strings.IndexOf ("c"), current = n.GetNextMatchingItem (current, 'c'));
 			Assert.Equal ("c", n.SearchString);
 			Assert.Equal (strings.IndexOf ("can"), current = n.GetNextMatchingItem (current, 'a'));