mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
Fix Ctrl being ignored in the range \u0001-\u001a
This commit is contained in:
@@ -8,7 +8,7 @@ internal class EscAsAltPattern : AnsiKeyboardParserPattern
|
||||
public EscAsAltPattern () { IsLastMinute = true; }
|
||||
|
||||
#pragma warning disable IDE1006 // Naming Styles
|
||||
private static readonly Regex _pattern = new (@"^\u001b([a-zA-Z0-9_])$");
|
||||
private static readonly Regex _pattern = new (@"^\u001b([\u0001-\u001aa-zA-Z0-9_])$");
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
|
||||
public override bool IsMatch (string? input) { return _pattern.IsMatch (input!); }
|
||||
@@ -22,7 +22,13 @@ internal class EscAsAltPattern : AnsiKeyboardParserPattern
|
||||
return null;
|
||||
}
|
||||
|
||||
char key = match.Groups [1].Value [0];
|
||||
char ch = match.Groups [1].Value [0];
|
||||
|
||||
Key key = ch switch
|
||||
{
|
||||
>= '\u0001' and <= '\u001a' => ((Key)(ch + 96)).WithCtrl,
|
||||
_ => ch
|
||||
};
|
||||
|
||||
return new Key (key).WithAlt;
|
||||
}
|
||||
|
||||
@@ -103,16 +103,24 @@ public class AnsiKeyboardParserTests
|
||||
yield return new object [] { "\u001b[1;2P", Key.F1.WithShift };
|
||||
yield return new object [] { "\u001b[1;3Q", Key.F2.WithAlt };
|
||||
yield return new object [] { "\u001b[1;5R", Key.F3.WithCtrl };
|
||||
|
||||
|
||||
// Keys with Alt modifiers
|
||||
yield return new object [] { "\u001ba", Key.A.WithAlt, true };
|
||||
yield return new object [] { "\u001bA", Key.A.WithShift.WithAlt, true };
|
||||
yield return new object [] { "\u001b1", Key.D1.WithAlt, true };
|
||||
|
||||
// Keys with Ctrl and Alt modifiers
|
||||
yield return new object [] { "\u001b\u0001", Key.A.WithCtrl.WithAlt, true };
|
||||
yield return new object [] { "\u001b\u001a", Key.Z.WithCtrl.WithAlt, true };
|
||||
}
|
||||
|
||||
// Consolidated test for all keyboard events (e.g., arrow keys)
|
||||
[Theory]
|
||||
[MemberData (nameof (GetKeyboardTestData))]
|
||||
public void ProcessKeyboardInput_ReturnsCorrectKey (string? input, Key? expectedKey)
|
||||
public void ProcessKeyboardInput_ReturnsCorrectKey (string? input, Key? expectedKey, bool isLastMinute = false)
|
||||
{
|
||||
// Act
|
||||
Key? result = _parser.IsKeyboard (input)?.GetKey (input);
|
||||
Key? result = _parser.IsKeyboard (input, isLastMinute)?.GetKey (input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (expectedKey, result); // Verify the returned key matches the expected one
|
||||
|
||||
Reference in New Issue
Block a user