Fixes #2069. KeyDown and KeyUp events must run before OnKeyDown and OnKeyUp.

This commit is contained in:
BDisp
2022-09-28 00:07:55 +01:00
parent da6e2d2de3
commit 702ef46727
3 changed files with 87 additions and 4 deletions

View File

@@ -3910,5 +3910,73 @@ This is a tes
Assert.True (viewCalled);
Assert.True (tvCalled);
}
[Fact, AutoInitShutdown]
public void KeyDown_And_KeyUp_Events_Must_Called_Before_OnKeyDown_And_OnKeyUp ()
{
var view = new DerivedView ();
view.KeyDown += (e) => {
Assert.Equal (Key.a, e.KeyEvent.Key);
Assert.False (view.IsKeyDown);
e.Handled = true;
};
view.KeyPress += (e) => {
Assert.Equal (Key.a, e.KeyEvent.Key);
Assert.False (view.IsKeyPress);
e.Handled = true;
};
view.KeyUp += (e) => {
Assert.Equal (Key.a, e.KeyEvent.Key);
Assert.False (view.IsKeyUp);
e.Handled = true;
};
var iterations = -1;
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
Console.MockKeyPresses.Push (new ConsoleKeyInfo ('a', ConsoleKey.A, false, false, false));
} else if (iterations == 1) {
Application.RequestStop ();
}
};
Application.Top.Add (view);
Assert.True (view.CanFocus);
Application.Run ();
Application.Shutdown ();
}
public class DerivedView : View {
public DerivedView ()
{
CanFocus = true;
}
public bool IsKeyDown { get; set; }
public bool IsKeyPress { get; set; }
public bool IsKeyUp { get; set; }
public override bool OnKeyDown (KeyEvent keyEvent)
{
IsKeyDown = true;
return base.OnKeyDown (keyEvent);
}
public override bool ProcessKey (KeyEvent keyEvent)
{
IsKeyPress = true;
return base.ProcessKey (keyEvent);
}
public override bool OnKeyUp (KeyEvent keyEvent)
{
IsKeyUp = true;
return base.OnKeyUp (keyEvent);
}
}
}
}