فهرست منبع

Merge pull request #3548 from BDisp/v2_3545_focused-view-sync-fix

Fixes #3545. Superview most focused view not sync with the overlapped view.
Tig 1 سال پیش
والد
کامیت
6835096b12

+ 1 - 0
Terminal.Gui/Application/Application.cs

@@ -530,6 +530,7 @@ public static partial class Application
         toplevel.LayoutSubviews ();
         toplevel.PositionToplevels ();
         toplevel.FocusFirst ();
+        BringOverlappedTopToFront ();
 
         if (refreshDriver)
         {

+ 6 - 1
Terminal.Gui/View/ViewSubViews.cs

@@ -438,7 +438,7 @@ public partial class View
                 SetHasFocus (false, this);
                 SuperView?.EnsureFocus ();
 
-                if (SuperView is { } && SuperView.Focused is null)
+                if (SuperView is { Focused: null })
                 {
                     SuperView.FocusNext ();
 
@@ -477,6 +477,11 @@ public partial class View
                         }
                     }
                 }
+
+                if (this is Toplevel && Application.Current.Focused != this)
+                {
+                    Application.BringOverlappedTopToFront ();
+                }
             }
 
             OnCanFocusChanged ();

+ 1 - 1
Terminal.Gui/Views/ToplevelOverlapped.cs

@@ -67,7 +67,7 @@ public static partial class Application
 
         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);
         }

+ 3 - 3
UnitTests/Application/KeyboardTests.cs

@@ -193,7 +193,7 @@ public class KeyboardTests
         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);
@@ -220,7 +220,7 @@ public class KeyboardTests
 
     [Fact]
     [AutoInitShutdown]
-    public void EnsuresTopOnFront_CanFocus_True_By_Keyboard_ ()
+    public void EnsuresTopOnFront_CanFocus_True_By_Keyboard ()
     {
         Toplevel top = new ();
 
@@ -253,7 +253,7 @@ public class KeyboardTests
         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);