Fixes #750. Ensure the correct focus order after call SetFocus.

This commit is contained in:
BDisp
2020-07-24 19:15:28 +01:00
parent 841ef3c85f
commit fa992abc6e

View File

@@ -1078,13 +1078,13 @@ namespace Terminal.Gui {
{
if (hasFocus != value) {
hasFocus = value;
if (value) {
OnEnter (view);
} else {
OnLeave (view);
}
SetNeedsDisplay ();
}
if (value) {
OnEnter (view);
} else {
OnLeave (view);
}
SetNeedsDisplay ();
// Remove focus down the chain of subviews if focus is removed
if (!value && focused != null) {
@@ -1303,7 +1303,8 @@ namespace Terminal.Gui {
}
/// <summary>
/// Causes the specified subview to have focus.
/// Causes the specified subview to have focus.
/// This does not ensures that the entire parent hierarchy can really get focus and thus not updating the focus order.
/// </summary>
/// <param name="view">View.</param>
public void SetFocus (View view)
@@ -1313,7 +1314,7 @@ namespace Terminal.Gui {
//Console.WriteLine ($"Request to focus {view}");
if (!view.CanFocus)
return;
if (focused == view)
if (focused?.hasFocus == true && focused == view)
return;
// Make sure that this view is a subview
@@ -1336,6 +1337,14 @@ namespace Terminal.Gui {
SuperView?.SetFocus (this);
}
/// <summary>
/// Causes the specified view and the entire parent hierarchy to have focus.
/// </summary>
public void SetFocus ()
{
SuperView?.SetFocus (this);
}
/// <summary>
/// Defines the event arguments for <see cref="KeyEvent"/>
/// </summary>
@@ -1449,11 +1458,13 @@ namespace Terminal.Gui {
/// </summary>
public void EnsureFocus ()
{
if (focused == null)
if (FocusDirection == Direction.Forward)
if (focused == null && subviews?.Count > 0) {
if (FocusDirection == Direction.Forward) {
FocusFirst ();
else
} else {
FocusLast ();
}
}
}
/// <summary>