~sircmpwn/aerc

Fix tab refocus on remove v1 PROPOSED

Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/%3C20191008173040.757012-1-dev%40jeffas.io%3E/mbox | git am -3
Learn more about email & git

[PATCH] Fix tab refocus on remove Export this patch

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 don't need to change the currently
selected tab.
---
 lib/ui/tab.go | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 9c19cd7..5e64c41 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -63,10 +63,12 @@ func (tabs *Tabs) invalidateChild(d Drawable) {

 func (tabs *Tabs) Remove(content Drawable) {
 	match := false
+	tabIndex := 0
 	for i, tab := range tabs.Tabs {
 		if tab.Content == content {
 			tabs.Tabs = append(tabs.Tabs[:i], tabs.Tabs[i+1:]...)
 			tabs.removeHistory(i)
+			tabIndex = i
 			match = true
 			break
 		}
@@ -74,12 +76,15 @@ func (tabs *Tabs) Remove(content Drawable) {
 	if !match {
 		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 tabIndex == 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)
+			}
 		}
 	}
 	tabs.TabStrip.Invalidate()
--
2.23.0
View this thread in the archives