mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 07:47:54 +01:00
* Fixes #2252. Pressing the ENTER key in a TextField should not move the focus * Update xml doc. * Tested on WSL-Ubuntu-20.04
This commit is contained in:
@@ -129,6 +129,10 @@ namespace Terminal.Gui {
|
||||
/// Gets or sets whether the <see cref="Button"/> is the default action to activate in a dialog.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if is default; otherwise, <c>false</c>.</value>
|
||||
/// <remarks>
|
||||
/// If is <see langword="true"/> the current focused view
|
||||
/// will remain focused if the window is not closed.
|
||||
/// </remarks>
|
||||
public bool IsDefault {
|
||||
get => is_default;
|
||||
set {
|
||||
@@ -219,7 +223,7 @@ namespace Terminal.Gui {
|
||||
|
||||
bool AcceptKey ()
|
||||
{
|
||||
if (!HasFocus) {
|
||||
if (!IsDefault && !HasFocus) {
|
||||
SetFocus ();
|
||||
}
|
||||
OnClicked ();
|
||||
|
||||
@@ -585,5 +585,21 @@ namespace Terminal.Gui.ViewTests {
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void IsDefault_True_Does_Not_Get_The_Focus_On_Enter_Key ()
|
||||
{
|
||||
var wasClicked = false;
|
||||
var view = new View { CanFocus = true };
|
||||
var btn = new Button { Text = "Ok", IsDefault = true };
|
||||
btn.Clicked += () => wasClicked = true;
|
||||
Application.Top.Add (view, btn);
|
||||
Application.Begin (Application.Top);
|
||||
Assert.True (view.HasFocus);
|
||||
|
||||
Application.Top.ProcessColdKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
|
||||
Assert.True (view.HasFocus);
|
||||
Assert.True (wasClicked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
"type": "wsl",
|
||||
"wslDistribution": "Ubuntu"
|
||||
},
|
||||
{
|
||||
"name": "WSL-Ubuntu-20.04",
|
||||
"type": "wsl",
|
||||
"wslDistribution": "Ubuntu-20.04"
|
||||
},
|
||||
{
|
||||
"name": "WSL-Debian",
|
||||
"type": "wsl",
|
||||
|
||||
Reference in New Issue
Block a user