Skip to content

Commit e8ef793

Browse files
committed
Fixes #1984. Added ClearOnVisibleFalse to flag if the view must be cleared or not.
1 parent d2bd7b2 commit e8ef793

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

Terminal.Gui/Core/View.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ public void ClearKeybinding (Key key)
18201820
/// <param name="command"></param>
18211821
public void ClearKeybinding (params Command [] command)
18221822
{
1823-
foreach (var kvp in KeyBindings.Where (kvp => kvp.Value.SequenceEqual (command)).ToArray()) {
1823+
foreach (var kvp in KeyBindings.Where (kvp => kvp.Value.SequenceEqual (command)).ToArray ()) {
18241824
KeyBindings.Remove (kvp.Key);
18251825
}
18261826
}
@@ -2556,6 +2556,11 @@ public override bool Enabled {
25562556
}
25572557
}
25582558

2559+
/// <summary>
2560+
/// Gets or sets whether a view is cleared if the <see cref="Visible"/> property is <see langword="false"/>.
2561+
/// </summary>
2562+
public bool ClearOnVisibleFalse { get; set; } = true;
2563+
25592564
/// <inheritdoc/>>
25602565
public override bool Visible {
25612566
get => base.Visible;
@@ -2566,7 +2571,9 @@ public override bool Visible {
25662571
if (HasFocus) {
25672572
SetHasFocus (false, this);
25682573
}
2569-
Clear ();
2574+
if (ClearOnVisibleFalse) {
2575+
Clear ();
2576+
}
25702577
}
25712578
OnVisibleChanged ();
25722579
SetNeedsDisplay ();

UnitTests/ViewTests.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,6 +3830,66 @@ public void Visible_Clear_The_View_Output ()
38303830
│ │
38313831
│ │
38323832
└────────────────────────────┘
3833+
", output);
3834+
}
3835+
3836+
[Fact, AutoInitShutdown]
3837+
public void ClearOnVisibleFalse_Gets_Sets ()
3838+
{
3839+
var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
3840+
var label = new Label (text);
3841+
Application.Top.Add (label);
3842+
3843+
var sbv = new ScrollBarView (label, true, false) {
3844+
Size = 100,
3845+
ClearOnVisibleFalse = false
3846+
};
3847+
Application.Begin (Application.Top);
3848+
3849+
Assert.True (sbv.Visible);
3850+
GraphViewTests.AssertDriverContentsWithFrameAre (@"
3851+
This is a tes▲
3852+
This is a tes┬
3853+
This is a tes┴
3854+
This is a tes░
3855+
This is a tes░
3856+
This is a tes▼
3857+
", output);
3858+
3859+
sbv.Visible = false;
3860+
Assert.False (sbv.Visible);
3861+
Application.Top.Redraw (Application.Top.Bounds);
3862+
GraphViewTests.AssertDriverContentsWithFrameAre (@"
3863+
This is a test
3864+
This is a test
3865+
This is a test
3866+
This is a test
3867+
This is a test
3868+
This is a test
3869+
", output);
3870+
3871+
sbv.Visible = true;
3872+
Assert.True (sbv.Visible);
3873+
Application.Top.Redraw (Application.Top.Bounds);
3874+
GraphViewTests.AssertDriverContentsWithFrameAre (@"
3875+
This is a tes▲
3876+
This is a tes┬
3877+
This is a tes┴
3878+
This is a tes░
3879+
This is a tes░
3880+
This is a tes▼
3881+
", output);
3882+
3883+
sbv.ClearOnVisibleFalse = true;
3884+
sbv.Visible = false;
3885+
Assert.False (sbv.Visible);
3886+
GraphViewTests.AssertDriverContentsWithFrameAre (@"
3887+
This is a tes
3888+
This is a tes
3889+
This is a tes
3890+
This is a tes
3891+
This is a tes
3892+
This is a tes
38333893
", output);
38343894
}
38353895
}

0 commit comments

Comments
 (0)