From c348cda31795f7b5b568567441809f6ad6754acc Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 15 Nov 2023 15:29:26 +0000 Subject: [PATCH] Fixes #2987. Set a MdiChild visible to false still processes keystrokes. (#2988) --- Terminal.Gui/Core/Application.cs | 2 +- UnitTests/TopLevels/MdiTests.cs | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 8cc89a64f..d01b338a2 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -531,7 +531,7 @@ namespace Terminal.Gui { return; } - var chain = toplevels.ToList (); + var chain = toplevels.Where (t => t.Visible).ToList (); foreach (var topLevel in chain) { if (topLevel.ProcessHotKey (ke)) { EnsuresMdiTopOnFrontIfMdiTopMostFocused (); diff --git a/UnitTests/TopLevels/MdiTests.cs b/UnitTests/TopLevels/MdiTests.cs index 2564def24..2acd3d397 100644 --- a/UnitTests/TopLevels/MdiTests.cs +++ b/UnitTests/TopLevels/MdiTests.cs @@ -692,5 +692,48 @@ namespace Terminal.Gui.TopLevelTests { Assert.Empty (Application.MdiChildes); } + + [Fact, AutoInitShutdown] + public void MdiChild_Set_Visible_False_Does_Not_Process_Keys () + { + var count = 0; + var mdi = new Mdi (); + var button = new Button (); + button.Clicked += () => count++; + var child = new Window (); + child.Add (button); + var iterations = -1; + Application.Iteration += () => { + iterations++; + if (iterations == 0) { + Application.Run (child); + } else if (iterations == 1) { + Assert.Equal (child, Application.Current); + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessKeyEvent", + new KeyEvent (Key.Enter, new KeyModifiers ())); + } else if (iterations == 2) { + Assert.Equal (child, Application.Current); + Assert.True (child.Visible); + child.Visible = false; + } else if (iterations == 3) { + Assert.Equal (mdi, Application.Current); + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessKeyEvent", + new KeyEvent (Key.Enter, new KeyModifiers ())); + } else if (iterations == 4) { + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessKeyEvent", + new KeyEvent (Application.QuitKey, new KeyModifiers ())); + } + }; + Application.Run (mdi); + Assert.Equal (4, iterations); + Assert.Equal (1, count); + } + } }