فهرست منبع

Merge pull request #3405 from tznind/fix-tab-remove-null-ref

Fixes #3365 - Fix null reference removing tab
Tig 1 سال پیش
والد
کامیت
ffaf756898
2فایلهای تغییر یافته به همراه21 افزوده شده و 1 حذف شده
  1. 1 1
      Terminal.Gui/Views/TabView.cs
  2. 20 0
      UnitTests/Views/TabViewTests.cs

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

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

+ 20 - 0
UnitTests/Views/TabViewTests.cs

@@ -1269,6 +1269,26 @@ public class TabViewTests
         Application.Shutdown ();
         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 () { return GetTabView (out _, out _); }
 
 
     private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = true)
     private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = true)