浏览代码

Combine to one non-destructive mutation

Brandon Thetford 1 年之前
父节点
当前提交
6865391bd1
共有 1 个文件被更改,包括 6 次插入7 次删除
  1. 6 7
      Terminal.Gui/Drawing/LineCanvas.cs

+ 6 - 7
Terminal.Gui/Drawing/LineCanvas.cs

@@ -85,14 +85,13 @@ public class LineCanvas : IDisposable
                     bounds = Rectangle.Union (bounds, _lines [i].Bounds);
                 }
 
-                if (bounds.Width == 0)
+                if (bounds is {Width: 0} or {Height: 0})
                 {
-                    bounds.Width = 1;
-                }
-
-                if (bounds.Height == 0)
-                {
-                    bounds.Height = 1;
+                    bounds = bounds with
+                    {
+                        Width = Math.Clamp (bounds.Width, 1, short.MaxValue),
+                        Height = Math.Clamp (bounds.Height, 1, short.MaxValue)
+                    };
                 }
 
                 _cachedBounds = bounds;