diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs index 51e0ac6c7..110627bd9 100644 --- a/Terminal.Gui/Application/Application.Run.cs +++ b/Terminal.Gui/Application/Application.Run.cs @@ -186,11 +186,13 @@ public static partial class Application // Run (Begin, Run, End, Stop) toplevel.LayoutSubviews (); toplevel.PositionToplevels (); - // Try to set initial focus to any TabGroup - if (!toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup)) + + // TODO: Should this use FindDeepestFocusableView instead? + // Try to set initial focus to any TabStop + if (!toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop)) { - // That didn't work. Try TabStop. - toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); + // That didn't work. Try TabGroup. + toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup); } ApplicationOverlapped.BringOverlappedTopToFront (); diff --git a/UnitTests/View/Navigation/NavigationTests.cs b/UnitTests/View/Navigation/NavigationTests.cs index cdc639b53..5ddec1bef 100644 --- a/UnitTests/View/Navigation/NavigationTests.cs +++ b/UnitTests/View/Navigation/NavigationTests.cs @@ -604,6 +604,28 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews Application.Shutdown (); } + + [Fact] + [AutoInitShutdown] + public void Application_Begin_FocusesDeepest () + { + var win1 = new Window { Id = "win1", Width = 10, Height = 1 }; + var view1 = new View { Id = "view1", Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true }; + var win2 = new Window { Id = "win2", Y = 6, Width = 10, Height = 1 }; + var view2 = new View { Id = "view2", Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true }; + win2.Add (view2); + win1.Add (view1, win2); + + Application.Begin (win1); + + Assert.True (win1.HasFocus); + Assert.True (view1.HasFocus); + Assert.False (win2.HasFocus); + Assert.False (view2.HasFocus); + win1.Dispose (); + } + + #if V2_NEW_FOCUS_IMPL // bogus test - Depends on auto setting of CanFocus [Fact] [AutoInitShutdown] diff --git a/UnitTests/Views/WindowTests.cs b/UnitTests/Views/WindowTests.cs index a010227f7..554593d23 100644 --- a/UnitTests/Views/WindowTests.cs +++ b/UnitTests/Views/WindowTests.cs @@ -201,24 +201,4 @@ public class WindowTests Assert.Null (windowWithFrame1234.MostFocused); Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrame1234.TextDirection); } - - [Fact] - [AutoInitShutdown] - public void OnCanFocusChanged_Only_Must_ContentView_Forces_SetFocus_After_IsInitialized_Is_True () - { - var win1 = new Window { Id = "win1", Width = 10, Height = 1 }; - var view1 = new View { Id = "view1", Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true }; - var win2 = new Window { Id = "win2", Y = 6, Width = 10, Height = 1 }; - var view2 = new View { Id = "view2", Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true }; - win2.Add (view2); - win1.Add (view1, win2); - - Application.Begin (win1); - - Assert.True (win1.HasFocus); - Assert.True (view1.HasFocus); - Assert.False (win2.HasFocus); - Assert.False (view2.HasFocus); - win1.Dispose (); - } }