Просмотр исходного кода

Fixed latent bug in ScrollBarView

Tig 1 год назад
Родитель
Сommit
1ffabac38b
2 измененных файлов с 13 добавлено и 7 удалено
  1. 4 7
      Terminal.Gui/Views/ListView.cs
  2. 9 0
      Terminal.Gui/Views/ScrollBarView.cs

+ 4 - 7
Terminal.Gui/Views/ListView.cs

@@ -273,7 +273,10 @@ public class ListView : View
         }
         }
     }
     }
 
 
-    /// <summary>Gets or sets the item that is displayed at the top of the <see cref="ListView"/>.</summary>
+    /// <summary>Gets or sets the index of the item that will appear at the top of the <see cref="View.Viewport"/>.</summary>
+    /// <remarks>
+    /// This a helper property for accessing <c>listView.Viewport.Y</c>.
+    /// </remarks>
     /// <value>The top item.</value>
     /// <value>The top item.</value>
     public int TopItem
     public int TopItem
     {
     {
@@ -285,13 +288,7 @@ public class ListView : View
                 return;
                 return;
             }
             }
 
 
-            if (value < 0 || (_source.Count > 0 && value >= _source.Count))
-            {
-                throw new ArgumentException ("value");
-            }
-
             Viewport = Viewport with { Y = value };
             Viewport = Viewport with { Y = value };
-            SetNeedsDisplay ();
         }
         }
     }
     }
 
 

+ 9 - 0
Terminal.Gui/Views/ScrollBarView.cs

@@ -204,6 +204,11 @@ public class ScrollBarView : View
         get => _position;
         get => _position;
         set
         set
         {
         {
+            if (_position == value)
+            {
+                return;
+            }
+
             _position = value;
             _position = value;
 
 
             if (IsInitialized)
             if (IsInitialized)
@@ -900,6 +905,10 @@ public class ScrollBarView : View
     // Helper to assist Initialized event handler
     // Helper to assist Initialized event handler
     private void SetPosition (int newPosition)
     private void SetPosition (int newPosition)
     {
     {
+        if (newPosition < 0)
+        {
+            return;
+        }
         if (CanScroll (newPosition - _position, out int max, _vertical))
         if (CanScroll (newPosition - _position, out int max, _vertical))
         {
         {
             if (max == newPosition - _position)
             if (max == newPosition - _position)