Skip to content

Commit 93eb6be

Browse files
committed
Fix TabControl not firing TabChanged for first tab
_activeTabIndex initialized to 0 instead of -1, so setting ActiveTabIndex = 0 after adding the first tab was a no-op. Changed initial value to -1 and added bounds guards.
1 parent cdba696 commit 93eb6be

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

SharpConsoleUI/Controls/TabControl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class TabControl : IWindowControl, IContainer, IDOMPaintable,
4141
IFocusableControl, IFocusableContainerWithHeader
4242
{
4343
private readonly List<TabPage> _tabPages = new();
44-
private int _activeTabIndex = 0;
44+
private int _activeTabIndex = -1;
4545
private TabHeaderStyle _headerStyle = TabHeaderStyle.Classic;
4646

4747
// IWindowControl properties
@@ -127,7 +127,7 @@ public int ActiveTabIndex
127127
return;
128128

129129
// Toggle visibility
130-
if (_activeTabIndex < _tabPages.Count)
130+
if (_activeTabIndex >= 0 && _activeTabIndex < _tabPages.Count)
131131
_tabPages[_activeTabIndex].Content.Visible = false;
132132

133133
_activeTabIndex = value;
@@ -221,7 +221,7 @@ public void RemoveTab(int index)
221221
// Adjust active tab index
222222
if (_tabPages.Count == 0)
223223
{
224-
_activeTabIndex = 0;
224+
_activeTabIndex = -1;
225225
}
226226
else if (index == _activeTabIndex)
227227
{
@@ -544,7 +544,7 @@ public System.Drawing.Size GetLogicalContentSize()
544544
int width = _width ?? ContentWidth ?? 0;
545545
int height = _height ?? (TabHeaderHeight + 10); // Default height if not specified
546546

547-
if (!_height.HasValue && _activeTabIndex < _tabPages.Count)
547+
if (!_height.HasValue && _activeTabIndex >= 0 && _activeTabIndex < _tabPages.Count)
548548
{
549549
// Dynamic sizing based on active tab
550550
var activeTabSize = _tabPages[_activeTabIndex].Content.GetLogicalContentSize();

0 commit comments

Comments
 (0)