diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index e59ae60a67..252e6f4680 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -2562,8 +2562,11 @@ public override bool Visible { set { if (base.Visible != value) { base.Visible = value; - if (!value && HasFocus) { - SetHasFocus (false, this); + if (!value) { + if (HasFocus) { + SetHasFocus (false, this); + } + Clear (); } OnVisibleChanged (); SetNeedsDisplay (); diff --git a/UnitTests/ViewTests.cs b/UnitTests/ViewTests.cs index 8b0c4ee113..e0cfecce45 100644 --- a/UnitTests/ViewTests.cs +++ b/UnitTests/ViewTests.cs @@ -3803,5 +3803,34 @@ e n ", output); } + [Fact, AutoInitShutdown] + public void Visible_Clear_The_View_Output () + { + var label = new Label ("Testing visibility."); + var win = new Window (); + win.Add (label); + var top = Application.Top; + top.Add (win); + Application.Begin (top); + + Assert.True (label.Visible); + ((FakeDriver)Application.Driver).SetBufferSize (30, 5); + GraphViewTests.AssertDriverContentsWithFrameAre (@" +┌────────────────────────────┐ +│Testing visibility. │ +│ │ +│ │ +└────────────────────────────┘ +", output); + + label.Visible = false; + GraphViewTests.AssertDriverContentsWithFrameAre (@" +┌────────────────────────────┐ +│ │ +│ │ +│ │ +└────────────────────────────┘ +", output); + } } }