summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-07-05 20:23:40 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-10 21:15:05 +0200
commitd7feb56cbe7b81160b580ec2f5dcaef78c7a2230 (patch)
tree8e5ea08f8ff55bfbeac9603efdfbbe7ef9e7a581
parentaae46c7afdf4f64a49384afde41984edf936da76 (diff)
downloadaerc-d7feb56cbe7b81160b580ec2f5dcaef78c7a2230.zip
fix panic on closing a tab
This change fixes a panic caused by the selected tab being out of sync when selecting a new one in widgets.(*Aerc).SelectedTab(). This happens if the tab is already removed from the list of tabs, but the selection not yet being updated. This was achieved by moving the tabs behind updating the selection. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
-rw-r--r--lib/ui/tab.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index a67bdab..3be512f 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -74,10 +74,13 @@ func (tabs *Tabs) invalidateChild(d Drawable) {
func (tabs *Tabs) Remove(content Drawable) {
indexToRemove := -1
+ removeTab := func() {}
for i, tab := range tabs.Tabs {
if tab.Content == content {
- tabs.Tabs = append(tabs.Tabs[:i], tabs.Tabs[i+1:]...)
- tabs.removeHistory(i)
+ removeTab = func() {
+ tabs.Tabs = append(tabs.Tabs[:i], tabs.Tabs[i+1:]...)
+ tabs.removeHistory(i)
+ }
indexToRemove = i
break
}
@@ -99,6 +102,7 @@ func (tabs *Tabs) Remove(content Drawable) {
// selected tab is now one to the left of where it was
tabs.Selected--
}
+ removeTab()
tabs.TabStrip.Invalidate()
}