Pārlūkot izejas kodu

Merge branch 'v2_develop' into v2_3269_Bounds-ContentArea

Tig 1 gadu atpakaļ
vecāks
revīzija
a655120e48

+ 8 - 4
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -273,7 +273,8 @@ public partial class View
 
             if (AutoSize)
             {
-                throw new InvalidOperationException (@$"Must set AutoSize to false before setting {nameof (Height)}.");
+                Debug.WriteLine (@$"Must set AutoSize to false before setting {nameof (Height)}.");
+                AutoSize = false;
             }
 
             //if (ValidatePosDim) {
@@ -281,9 +282,10 @@ public partial class View
 
             if (IsAdded && AutoSize && !isValidNewAutoSize)
             {
-                throw new InvalidOperationException (
+                Debug.WriteLine (
                                                      @$"Must set AutoSize to false before setting the {nameof (Height)}."
                                                     );
+                AutoSize = false;
             }
 
             //}
@@ -328,14 +330,16 @@ public partial class View
 
             if (AutoSize)
             {
-                throw new InvalidOperationException (@$"Must set AutoSize to false before setting {nameof (Width)}.");
+                Debug.WriteLine($@"Must set AutoSize to false before setting {nameof(Width)}.");
+                AutoSize = false;
             }
 
             bool isValidNewAutoSize = AutoSize && IsValidAutoSizeWidth (_width);
 
             if (IsAdded && AutoSize && !isValidNewAutoSize)
             {
-                throw new InvalidOperationException (@$"Must set AutoSize to false before setting {nameof (Width)}.");
+                Debug.WriteLine($@"Must set AutoSize to false before setting {nameof(Width)}.");
+                AutoSize = false;
             }
 
             OnResizeNeeded ();

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

@@ -888,7 +888,7 @@ public class ListWrapper : IListDataSource
         int start = 0
     )
     {
-        container.Move (col, line);
+        container.Move (Math.Max (col - start, 0), line);
         object t = _source? [item];
 
         if (t is null)
@@ -1004,8 +1004,9 @@ public class ListWrapper : IListDataSource
 
     private void RenderUstr (ConsoleDriver driver, string ustr, int col, int line, int width, int start = 0)
     {
-        string str = start > ustr.GetColumns () ? string.Empty : ustr.Substring (start);
-        string u = TextFormatter.ClipAndJustify (str, width, TextAlignment.Left); driver.AddStr (u);
+        string str = start > ustr.GetColumns () ? string.Empty : ustr.Substring (Math.Min (start, ustr.ToRunes ().Length - 1));
+        string u = TextFormatter.ClipAndJustify (str, width, TextAlignment.Left);
+        driver.AddStr (u);
         width -= u.GetColumns ();
 
         while (width-- > 0)

+ 1 - 1
Terminal.Gui/Views/TabView.cs

@@ -177,7 +177,7 @@ public class TabView : View
             {
                 if (old?.HasFocus == true)
                 {
-                    SelectedTab.SetFocus ();
+                    SelectedTab?.SetFocus ();
                 }
 
                 OnSelectedTabChanged (old, value);

+ 2 - 2
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -84,9 +84,9 @@ public class ListViewWithSelection : Scenario
 
         _listView.DrawContent += (s, e) =>
                                  {
-                                     scrollBar.Size = _listView.Source.Count - 1;
+                                     scrollBar.Size = _listView.Source.Count;
                                      scrollBar.Position = _listView.TopItem;
-                                     scrollBar.OtherScrollBarView.Size = _listView.MaxLength - 1;
+                                     scrollBar.OtherScrollBarView.Size = _listView.MaxLength;
                                      scrollBar.OtherScrollBarView.Position = _listView.LeftItem;
                                      scrollBar.Refresh ();
                                  };

+ 35 - 0
UnitTests/Views/ListViewTests.cs

@@ -759,4 +759,39 @@ Item 6",
         Assert.Equal ("Three", selected);
         Assert.Equal (2, lv.SelectedItem);
     }
+
+    [Fact]
+    [AutoInitShutdown]
+    public void LeftItem_TopItem_Tests ()
+    {
+        var source = new List<string> ();
+        for (int i = 0; i < 5; i++) {
+            source.Add ($"Item {i}");
+        }
+        var lv = new ListView () {
+            X = 1,
+            Width = 10,
+            Height = 5,
+            Source = new ListWrapper (source)
+        };
+        var top = new Toplevel ();
+        top.Add (lv);
+        Application.Begin (top);
+
+        TestHelpers.AssertDriverContentsWithFrameAre (@"
+ Item 0
+ Item 1
+ Item 2
+ Item 3
+ Item 4", _output);
+
+        lv.LeftItem = 1;
+        lv.TopItem = 1;
+        Application.Refresh ();
+        TestHelpers.AssertDriverContentsWithFrameAre (@"
+ tem 1
+ tem 2
+ tem 3
+ tem 4", _output);
+    }
 }

+ 20 - 0
UnitTests/Views/TabViewTests.cs

@@ -1269,6 +1269,26 @@ public class TabViewTests
         Application.Shutdown ();
     }
 
+    [Fact]
+    public void RemoveTab_ThatHasFocus ()
+    {
+        TabView tv = GetTabView (out Tab _, out Tab tab2);
+
+        tv.SelectedTab = tab2;
+        tab2.HasFocus = true;
+
+        Assert.Equal (2, tv.Tabs.Count);
+        foreach (var t in tv.Tabs.ToArray ())
+        {
+            tv.RemoveTab (t);
+        }
+
+        Assert.Empty (tv.Tabs);
+
+        // Shutdown must be called to safely clean up Application if Init has been called
+        Application.Shutdown ();
+    }
+
     private TabView GetTabView () { return GetTabView (out _, out _); }
 
     private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = true)