Skip to content

Commit

Permalink
Fix null reference removing tab
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Apr 14, 2024
1 parent 0a73396 commit caddcdb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/TabView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public Tab SelectedTab
{
if (old?.HasFocus == true)
{
SelectedTab.SetFocus ();
SelectedTab?.SetFocus ();
}

OnSelectedTabChanged (old, value);
Expand Down
20 changes: 20 additions & 0 deletions UnitTests/Views/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,26 @@ public void SwitchTabBy_OutOfTabsRange ()
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)
Expand Down

0 comments on commit caddcdb

Please sign in to comment.