Fix tab refocus on remove
Previously removing a tab would always pop from the history of tabs. This checks to see if the closing tab is the one selected, if it is then we use the history, otherwise we only need to change the selected tab if it was after (to the right of) the closing tab, in which case we just decrement the selected index.
This commit is contained in:
parent
2542c65af2
commit
03d182ca88
1 changed files with 14 additions and 8 deletions
|
@ -62,18 +62,20 @@ func (tabs *Tabs) invalidateChild(d Drawable) {
|
|||
}
|
||||
|
||||
func (tabs *Tabs) Remove(content Drawable) {
|
||||
match := false
|
||||
indexToRemove := -1
|
||||
for i, tab := range tabs.Tabs {
|
||||
if tab.Content == content {
|
||||
tabs.Tabs = append(tabs.Tabs[:i], tabs.Tabs[i+1:]...)
|
||||
tabs.removeHistory(i)
|
||||
match = true
|
||||
indexToRemove = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if !match {
|
||||
if indexToRemove < 0 {
|
||||
return
|
||||
}
|
||||
// only pop the tab history if the closing tab is selected
|
||||
if indexToRemove == tabs.Selected {
|
||||
index, ok := tabs.popHistory()
|
||||
if ok {
|
||||
tabs.Select(index)
|
||||
|
@ -82,6 +84,10 @@ func (tabs *Tabs) Remove(content Drawable) {
|
|||
interactive.Focus(true)
|
||||
}
|
||||
}
|
||||
} else if indexToRemove < tabs.Selected {
|
||||
// selected tab is now one to the left of where it was
|
||||
tabs.Selected--
|
||||
}
|
||||
tabs.TabStrip.Invalidate()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue