From bedeca61e6152c7f7612e150d0db8ff5d4ae4fbe Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 15 Jan 2021 23:04:49 +0000 Subject: [PATCH] Fixing some bugs. --- Terminal.Gui/Core/View.cs | 2 +- Terminal.Gui/Views/ScrollBarView.cs | 5 +++-- UnitTests/ScrollBarViewTests.cs | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index b4ccd5f0d..cefddbe3a 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -741,7 +741,7 @@ namespace Terminal.Gui { public void SetChildNeedsDisplay () { ChildNeedsDisplay = true; - if (container != null && !container.ChildNeedsDisplay) + if (container != null) container.SetChildNeedsDisplay (); } diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index b9e48d84f..006dce1f8 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -448,7 +448,7 @@ namespace Terminal.Gui { return false; } - if (!Host.HasFocus) { + if (Host != null && !Host.HasFocus) { Host.SetFocus (); } @@ -537,7 +537,8 @@ namespace Terminal.Gui { internal bool CanScroll (int n, out int max, bool isVertical = false) { if (Host == null) { - throw new ArgumentNullException ("The host can't be null."); + max = 0; + return false; } var s = isVertical ? (KeepContentAlwaysInViewport ? Host.Bounds.Height + (showBothScrollIndicator ? -2 : -1) : 0) : diff --git a/UnitTests/ScrollBarViewTests.cs b/UnitTests/ScrollBarViewTests.cs index db278609b..0d963cf05 100644 --- a/UnitTests/ScrollBarViewTests.cs +++ b/UnitTests/ScrollBarViewTests.cs @@ -118,11 +118,13 @@ namespace Terminal.Gui { } [Fact] - public void Scrolling_With_Default_Constructor_Throws_ArgumentNullException () + public void Scrolling_With_Default_Constructor_Do_Not_Scroll () { - var sbv = new ScrollBarView (); - - Assert.Throws ("The host can't be null.", () => sbv.Position = 1); + var sbv = new ScrollBarView { + Position = 1 + }; + Assert.NotEqual (1, sbv.Position); + Assert.Equal (0, sbv.Position); } [Fact]