Преглед изворни кода

Fix bug where some key were not been split.

BDisp пре 9 месеци
родитељ
комит
808896d800

+ 5 - 1
Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs

@@ -338,6 +338,8 @@ public static class EscSeqUtils
 
                 if (!string.IsNullOrEmpty (terminator))
                 {
+                    System.Diagnostics.Debug.Assert (terminator.Length == 1);
+
                     key = GetConsoleKey (terminator [0], values [0], ref mod, ref keyChar);
 
                     if (key != 0 && values.Length > 1)
@@ -1417,7 +1419,9 @@ public static class EscSeqUtils
                 split = AddAndClearSplit ();
                 splitList.Add (c.ToString ());
             }
-            else if (previousChar != '\u001B' && c < Key.Space)// uint n when n is > 0 and <= KeyEsc
+            else if ((previousChar != '\u001B' && c <= Key.Space) || (previousChar != '\u001B' && c == 127)
+                     || (char.IsLetter (previousChar) && char.IsLower (c) && char.IsLetter (c))
+                     || (!string.IsNullOrEmpty (split) && split.Length > 2 && char.IsLetter (previousChar) && char.IsLetter (c)))
             {
                 isEscSeq = false;
                 split = AddAndClearSplit ();

+ 8 - 6
UnitTests/Input/EscSeqUtilsTests.cs

@@ -1440,12 +1440,14 @@ public class EscSeqUtilsTests
         Assert.Equal (cki, expectedCkInfos [0]);
     }
 
-    [Fact]
-    public void SplitEscapeRawString_Multiple_Tests ()
+    [Theory]
+    [InlineData ("\r[<35;50;1m[<35;49;1m[<35;47;1m[<35;46;1m[<35;45;2m[<35;44;2m[<35;43;3m[<35;42;3m[<35;41;4m[<35;40;5m[<35;39;6m[<35;49;1m[<35;48;2m[<0;33;6M[<0;33;6mOC\r", "\r")]
+    [InlineData ("\r[<35;50;1m[<35;49;1m[<35;47;1m[<35;46;1m[<35;45;2m[<35;44;2m[<35;43;3m[<35;42;3m[<35;41;4m[<35;40;5m[<35;39;6m[<35;49;1m[<35;48;2m[<0;33;6M[<0;33;6mOCe", "e")]
+    [InlineData ("\r[<35;50;1m[<35;49;1m[<35;47;1m[<35;46;1m[<35;45;2m[<35;44;2m[<35;43;3m[<35;42;3m[<35;41;4m[<35;40;5m[<35;39;6m[<35;49;1m[<35;48;2m[<0;33;6M[<0;33;6mOCV", "V")]
+    [InlineData ("\r[<35;50;1m[<35;49;1m[<35;47;1m[<35;46;1m[<35;45;2m[<35;44;2m[<35;43;3m[<35;42;3m[<35;41;4m[<35;40;5m[<35;39;6m[<35;49;1m[<35;48;2m[<0;33;6M[<0;33;6mOC\u007f", "\u007f")]
+    [InlineData ("\r[<35;50;1m[<35;49;1m[<35;47;1m[<35;46;1m[<35;45;2m[<35;44;2m[<35;43;3m[<35;42;3m[<35;41;4m[<35;40;5m[<35;39;6m[<35;49;1m[<35;48;2m[<0;33;6M[<0;33;6mOC ", " ")]
+    public void SplitEscapeRawString_Multiple_Tests (string rawData, string expectedLast)
     {
-        string rawData =
-            "\r[<35;50;1m[<35;49;1m[<35;47;1m[<35;46;1m[<35;45;2m[<35;44;2m[<35;43;3m[<35;42;3m[<35;41;4m[<35;40;5m[<35;39;6m[<35;49;1m[<35;48;2m[<0;33;6M[<0;33;6mOC\r";
-
         List<string> splitList = EscSeqUtils.SplitEscapeRawString (rawData);
         Assert.Equal (18, splitList.Count);
         Assert.Equal ("\r", splitList [0]);
@@ -1465,7 +1467,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("\u001b[<0;33;6M", splitList [14]);
         Assert.Equal ("\u001b[<0;33;6m", splitList [15]);
         Assert.Equal ("\u001bOC", splitList [16]);
-        Assert.Equal ("\r", splitList [^1]);
+        Assert.Equal (expectedLast, splitList [^1]);
     }
 
     [Theory]