Przeglądaj źródła

Fixed FindDeepestView bugg I caused by unravelling the recursion

Tig 1 rok temu
rodzic
commit
25491bdac6

+ 19 - 21
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -635,37 +635,35 @@ public partial class View
                 viewportOffset = found.Parent.Frame.Location;
             }
 
-            if (start.InternalSubviews is { Count: > 0 })
-            {
-                int startOffsetX = x - (start.Frame.X + viewportOffset.X);
-                int startOffsetY = y - (start.Frame.Y + viewportOffset.Y);
+            int startOffsetX = x - (start.Frame.X + viewportOffset.X);
+            int startOffsetY = y - (start.Frame.Y + viewportOffset.Y);
 
-                for (int i = start.InternalSubviews.Count - 1; i >= 0; i--)
+            View? subview = null;
+            for (int i = start.InternalSubviews.Count - 1; i >= 0; i--)
+            {
+                if (start.InternalSubviews [i].Visible
+                    && start.InternalSubviews [i].Contains (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y))
                 {
-                    View nextStart = start.InternalSubviews [i];
-
-                    if (nextStart.Visible && nextStart.Contains (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y))
-                    {
-                        start = nextStart;
-                        x = startOffsetX;
-                        y = startOffsetY;
-
-                        break;
-                    }
+                    subview = start.InternalSubviews [i];
+                    x = startOffsetX;
+                    y = startOffsetY;
 
-                    if (i == 0)
-                    {
-                        return start; // If no visible subview is found, return the current start view
-                    }
+                    // start is the deepest subview under the mouse; stop searching the subviews
+                    break;
                 }
             }
-            else
+
+            if (subview is null)
             {
+                // No subview was found that's under the mouse, so we're done
                 return start;
             }
+
+            // We found a subview of start that's under the mouse, continue...
+            start = subview;
         }
 
-        return start;
+        return null;
     }
 
 #nullable restore

+ 0 - 4
Terminal.Gui/View/ViewDrawing.cs

@@ -418,10 +418,6 @@ public partial class View
     /// </param>
     public virtual void OnDrawContent (Rectangle viewport)
     {
-        if (Title == "View in Padding")
-        {
-
-        }
         if (NeedsDisplay)
         {
             if (SuperView is { })

+ 12 - 12
Terminal.Gui/Views/ListView.cs

@@ -290,7 +290,7 @@ public class ListView : View
                 throw new ArgumentException ("value");
             }
 
-            Viewport = Viewport with { Y = Math.Max (value, 0) };
+            Viewport = Viewport with { Y = value };
             SetNeedsDisplay ();
         }
     }
@@ -331,11 +331,11 @@ public class ListView : View
             if (_selected < Viewport.Y)
             {
                 // TODO: The Max check here is not needed because, by default, Viewport enforces staying w/in ContentArea (View.ScrollSettings).
-                Viewport = Viewport with { Y = Math.Max (_selected, 0) };
+                Viewport = Viewport with { Y = _selected };
             }
             else if (Viewport.Height > 0 && _selected >= Viewport.Y + Viewport.Height)
             {
-                Viewport = Viewport with { Y = Math.Max (_selected - Viewport.Height + 1, 0) };
+                Viewport = Viewport with { Y = _selected - Viewport.Height + 1};
             }
 
             LayoutStarted -= ListView_LayoutStarted;
@@ -470,7 +470,7 @@ public class ListView : View
             }
             else if (_selected < Viewport.Y)
             {
-                Viewport = Viewport with { Y = Math.Max (_selected, 0) };
+                Viewport = Viewport with { Y = _selected };
             }
 
             OnSelectedChanged ();
@@ -483,7 +483,7 @@ public class ListView : View
         }
         else if (_selected >= Viewport.Y + Viewport.Height)
         {
-            Viewport = Viewport with { Y = Math.Max (_source.Count - Viewport.Height, 0) };
+            Viewport = Viewport with { Y = _source.Count - Viewport.Height };
             SetNeedsDisplay ();
         }
 
@@ -500,7 +500,7 @@ public class ListView : View
 
             if (Viewport.Y + _selected > Viewport.Height - 1)
             {
-                Viewport = Viewport with { Y = Math.Max (_selected, 0) };
+                Viewport = Viewport with { Y = _selected };
             }
 
             OnSelectedChanged ();
@@ -517,7 +517,7 @@ public class ListView : View
         if (_selected != 0)
         {
             _selected = 0;
-            Viewport = Viewport with { Y = Math.Max (_selected, 0) };
+            Viewport = Viewport with { Y = _selected };
             OnSelectedChanged ();
             SetNeedsDisplay ();
         }
@@ -550,7 +550,7 @@ public class ListView : View
 
             if (_source.Count >= Viewport.Height)
             {
-                Viewport = Viewport with { Y = Math.Max (_selected, 0) };
+                Viewport = Viewport with { Y = _selected };
             }
             else
             {
@@ -578,7 +578,7 @@ public class ListView : View
         if (n != _selected)
         {
             _selected = n;
-            Viewport = Viewport with { Y = Math.Max (_selected, 0) };
+            Viewport = Viewport with { Y = _selected };
             OnSelectedChanged ();
             SetNeedsDisplay ();
         }
@@ -616,11 +616,11 @@ public class ListView : View
 
             if (_selected < Viewport.Y)
             {
-                Viewport = Viewport with { Y = Math.Max (_selected, 0) };
+                Viewport = Viewport with { Y = _selected };
             }
             else if (_selected > Viewport.Y + Viewport.Height)
             {
-                Viewport = Viewport with { Y = Math.Max (_selected - Viewport.Height + 1, 0) };
+                Viewport = Viewport with { Y = _selected - Viewport.Height + 1 };
             }
 
             OnSelectedChanged ();
@@ -628,7 +628,7 @@ public class ListView : View
         }
         else if (_selected < Viewport.Y)
         {
-            Viewport = Viewport with { Y = Math.Max (_selected, 0) };
+            Viewport = Viewport with { Y = _selected };
             SetNeedsDisplay ();
         }