diff options
author | Jeffas <dev@jeffas.io> | 2019-10-10 13:24:42 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-10-14 10:38:04 -0400 |
commit | 03d182ca88329db778e6d271e44b480223f31807 (patch) | |
tree | e6bbd022e2fb0cc0cfd011b1797021f27232370b /lib/ui/tab.go | |
parent | 2542c65af2c24c94d70e8ab51cc590fe8fc3bd28 (diff) |
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.
Diffstat (limited to 'lib/ui/tab.go')
-rw-r--r-- | lib/ui/tab.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go index ef9fcd8..27fb604 100644 --- a/lib/ui/tab.go +++ b/lib/ui/tab.go @@ -62,25 +62,31 @@ 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 } - index, ok := tabs.popHistory() - if ok { - tabs.Select(index) - interactive, ok := tabs.Tabs[tabs.Selected].Content.(Interactive) + // only pop the tab history if the closing tab is selected + if indexToRemove == tabs.Selected { + index, ok := tabs.popHistory() if ok { - interactive.Focus(true) + tabs.Select(index) + interactive, ok := tabs.Tabs[tabs.Selected].Content.(Interactive) + if ok { + 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() } |