From 3c8dde3b9916c107b16ee4383f94cd5de0c201b2 Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Fri, 18 Dec 2020 20:14:12 +0000 Subject: [PATCH] Move selected tab when number of tabs reduce When a tab is deleted, the higher index tabs move down one. If the selected is above the one deleted move it also down one to match the tabs --- widget/tabcontainer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/widget/tabcontainer.go b/widget/tabcontainer.go index d87d868689..df4f23b84f 100644 --- a/widget/tabcontainer.go +++ b/widget/tabcontainer.go @@ -122,10 +122,13 @@ func (c *TabContainer) Remove(item *TabItem) { // RemoveIndex removes tab by index func (c *TabContainer) RemoveIndex(index int) { - c.SetItems(append(c.Items[:index], c.Items[index+1:]...)) if c.current == index { c.setTabIndex(-1) } + if c.current > index { + c.setTabIndex(c.current - 1) + } + c.SetItems(append(c.Items[:index], c.Items[index+1:]...)) } // SetItems sets the container’s items and refreshes.