Fix null reference removing tab

This commit is contained in:
tznind
2024-04-14 21:46:50 +01:00
parent 0a73396375
commit caddcdb846
2 changed files with 21 additions and 1 deletions

View File

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

View File

@@ -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)