Fixes #3545. V1 Superview most focused view not sync with the overlapped view.

This commit is contained in:
BDisp
2024-06-17 23:00:14 +01:00
parent 2e1b1a8df4
commit abdb7db1b8
4 changed files with 15 additions and 10 deletions

View File

@@ -1037,6 +1037,7 @@ namespace Terminal.Gui {
toplevel.LayoutSubviews ();
toplevel.PositionToplevels ();
toplevel.WillPresent ();
EnsuresTopOnFront ();
if (refreshDriver) {
MdiTop?.OnChildLoaded (toplevel);
toplevel.OnLoaded ();

View File

@@ -394,6 +394,10 @@ namespace Terminal.Gui {
}
}
}
if (SuperView is Toplevel && Application.Current?.Focused != SuperView) {
Application.EnsuresTopOnFront ();
}
}
OnCanFocusChanged ();
SetNeedsDisplay ();

View File

@@ -104,7 +104,7 @@ namespace Terminal.Gui {
public override void OnCanFocusChanged ()
{
if (MostFocused == null && CanFocus && Visible) {
if (HasFocus && MostFocused == null && CanFocus && Visible) {
EnsureFocus ();
}

View File

@@ -771,28 +771,28 @@ namespace Terminal.Gui.ApplicationTests {
Assert.True (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.False (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, new KeyModifiers ()));
Assert.True (win.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, new KeyModifiers ()));
Assert.True (win.CanFocus);
Assert.True (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.False (win2.HasFocus);
Assert.Equal ("win", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
win2.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Pressed });
Assert.True (win.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
win2.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Released });
Assert.Null (Toplevel.dragPosition);
}
@@ -816,35 +816,35 @@ namespace Terminal.Gui.ApplicationTests {
Assert.True (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.False (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
win.CanFocus = false;
Assert.False (win.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, new KeyModifiers ()));
Assert.True (win2.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, new KeyModifiers ()));
Assert.False (win.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
win.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Pressed });
Assert.False (win.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
win2.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Released });
Assert.Null (Toplevel.dragPosition);
}