Bläddra i källkod

Fix ScrollBar that was returning more 2 position at end.

BDisp 11 månader sedan
förälder
incheckning
ae7a86f9a9
2 ändrade filer med 17 tillägg och 17 borttagningar
  1. 2 2
      Terminal.Gui/Views/Scroll/Scroll.cs
  2. 15 15
      UnitTests/Views/ScrollBarTests.cs

+ 2 - 2
Terminal.Gui/Views/Scroll/Scroll.cs

@@ -251,9 +251,9 @@ public class Scroll : View
     {
         int barSize = BarSize;
 
-        if (position + barSize > Size + (KeepContentInAllViewport ? 0 : barSize))
+        if (position + barSize > Size + (KeepContentInAllViewport ? 0 : barSize) - (SuperViewAsScrollBar is { } ? 2 : 0))
         {
-            return KeepContentInAllViewport ? Math.Max (Size - barSize, 0) : Math.Max (Size - 1, 0);
+            return KeepContentInAllViewport ? Math.Max (Size - barSize - (SuperViewAsScrollBar is { } ? 2 : 0), 0) : Math.Max (Size - 1, 0);
         }
 
         return position;

+ 15 - 15
UnitTests/Views/ScrollBarTests.cs

@@ -474,7 +474,7 @@ public class ScrollBarTests
 ▼",
                     MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition,
-                    12,
+                    10,
                     @"
@@ -516,7 +516,7 @@ public class ScrollBarTests
 ▼",
                     MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition,
-                    12,
+                    10,
                     @"
@@ -537,7 +537,7 @@ public class ScrollBarTests
                     @"
 ◄░░░░████►",
                     MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition,
-                    12,
+                    10,
                     @"
 ◄░░░░████►")]
     [InlineData (
@@ -803,7 +803,7 @@ public class ScrollBarTests
         Assert.Equal (0, scrollBar.Position);
 
         // ScrollButton increase
-        for (var i = 0; i < 13; i++)
+        for (var i = 0; i < 11; i++)
         {
             Application.OnMouseEvent (
                                       new ()
@@ -811,7 +811,7 @@ public class ScrollBarTests
                                           Position = orientation == Orientation.Vertical ? new (10, 19) : new (19, 10), Flags = MouseFlags.Button1Pressed
                                       });
 
-            if (i < 12)
+            if (i < 10)
             {
                 Assert.Equal (i + 1, scrollBar.Position);
             }
@@ -825,7 +825,7 @@ public class ScrollBarTests
             }
         }
 
-        for (var i = 12; i > -1; i--)
+        for (var i = 10; i > -1; i--)
         {
             Application.OnMouseEvent (new () { Position = new (10, 10), Flags = MouseFlags.Button1Pressed });
 
@@ -883,8 +883,8 @@ public class ScrollBarTests
     }
 
     [Theory]
-    [InlineData (Orientation.Vertical, 20, 12, 10)]
-    [InlineData (Orientation.Vertical, 40, 32, 30)]
+    [InlineData (Orientation.Vertical, 20, 10, 10)]
+    [InlineData (Orientation.Vertical, 40, 30, 30)]
     public void Position_Cannot_Be_Negative_Nor_Greater_Than_Size_Minus_Frame_Length_KeepContentInAllViewport_True (Orientation orientation, int size, int expectedPos1, int expectedPos2)
     {
         var scrollBar = new ScrollBar { Orientation = orientation, Height = 10, Size = size, KeepContentInAllViewport = true };
@@ -970,19 +970,19 @@ public class ScrollBarTests
 
         Reset ();
         scrollBar.Position = 11;
-        Assert.Equal (11, scrollBar.Position);
-        Assert.Equal (1, changing);
-        Assert.Equal (1, changed);
+        Assert.Equal (10, scrollBar.Position);
+        Assert.Equal (0, changing);
+        Assert.Equal (0, changed);
 
         Reset ();
         scrollBar.Position = 12;
-        Assert.Equal (12, scrollBar.Position);
-        Assert.Equal (1, changing);
-        Assert.Equal (1, changed);
+        Assert.Equal (10, scrollBar.Position);
+        Assert.Equal (0, changing);
+        Assert.Equal (0, changed);
 
         Reset ();
         scrollBar.Position = 13;
-        Assert.Equal (12, scrollBar.Position);
+        Assert.Equal (10, scrollBar.Position);
         Assert.Equal (0, changing);
         Assert.Equal (0, changed);