ee5b537d538baf38450a2ae655dee53a49aa9824 — Jeffas 3 months ago 4541519
Fix :close on terminal panic

Executing :close on a terminal would panic due to it already having been
removed.

This is also related to the fact that removing a tab doesn't check for
whether it actually found a tab to remove or not.
2 files changed, 5 insertions(+), 1 deletions(-)

M commands/terminal/close.go
M lib/ui/tab.go
M commands/terminal/close.go => commands/terminal/close.go +0 -1
@@ 26,6 26,5 @@ func (_ Close) Execute(aerc *widgets.Aerc, args []string) error {
 	}
 	term, _ := aerc.SelectedTab().(*widgets.Terminal)
 	term.Close(nil)
-	aerc.RemoveTab(term)
 	return nil
 }

M lib/ui/tab.go => lib/ui/tab.go +5 -0
@@ 57,13 57,18 @@ func (tabs *Tabs) invalidateChild(d Drawable) {
 }
 
 func (tabs *Tabs) Remove(content Drawable) {
+	match := false
 	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
 			break
 		}
 	}
+	if !match {
+		return
+	}
 	index, ok := tabs.popHistory()
 	if ok {
 		tabs.Select(index)