Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Terminal.Gui/Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ public static RunState Begin (Toplevel toplevel)
toplevel.LayoutSubviews ();
toplevel.PositionToplevels ();
toplevel.FocusFirst ();
BringOverlappedTopToFront ();

if (refreshDriver)
{
Expand Down
7 changes: 6 additions & 1 deletion Terminal.Gui/View/ViewSubViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public bool CanFocus
SetHasFocus (false, this);
SuperView?.EnsureFocus ();

if (SuperView is { } && SuperView.Focused is null)
if (SuperView is { Focused: null })
{
SuperView.FocusNext ();

Expand Down Expand Up @@ -477,6 +477,11 @@ public bool CanFocus
}
}
}

if (this is Toplevel && Application.Current.Focused != this)
{
Application.BringOverlappedTopToFront ();
}
}

OnCanFocusChanged ();
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/ToplevelOverlapped.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void BringOverlappedTopToFront ()

View top = FindTopFromView (Top?.MostFocused);

if (top is Toplevel && Top.Subviews.Count > 1 && Top.Subviews [Top.Subviews.Count - 1] != top)
if (top is Toplevel && Top.Subviews.Count > 1 && Top.Subviews [^1] != top)
{
Top.BringSubviewToFront (top);
}
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/Application/KeyboardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void EnsuresTopOnFront_CanFocus_False_By_Keyboard ()
Assert.True (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.False (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);

win.CanFocus = false;
Assert.False (win.CanFocus);
Expand All @@ -220,7 +220,7 @@ public void EnsuresTopOnFront_CanFocus_False_By_Keyboard ()

[Fact]
[AutoInitShutdown]
public void EnsuresTopOnFront_CanFocus_True_By_Keyboard_ ()
public void EnsuresTopOnFront_CanFocus_True_By_Keyboard ()
{
Toplevel top = new ();

Expand Down Expand Up @@ -253,7 +253,7 @@ public void EnsuresTopOnFront_CanFocus_True_By_Keyboard_ ()
Assert.True (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.False (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);

top.NewKeyDownEvent (Key.Tab.WithCtrl);
Assert.True (win.CanFocus);
Expand Down