fix: clear stale previous tab ids per window
Validate per-window previous tab ids before Alt+Tab uses them.
- commit
- 1e06425d829aec6dc90c1b3c780317d756fc994f
- author
- brice · · 2026-04-28 18:38 UTC
- parent
- cccb5fe
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +22 -3
M internal/ui/app.go +22 -3
| @@ -511,6 +511,19 @@ func (a *App) browserWindowForTab(tabID entity.TabID) *browserWindow { | |||
| 511 | 511 | return a.browserWindowForMainWindow(a.mainWindow) | |
| 512 | 512 | } | |
| 513 | 513 | ||
| 514 | + | func (a *App) browserWindowHasLiveTab(bw *browserWindow, tabID entity.TabID) bool { | |
| 515 | + | if a == nil || a.tabs == nil || bw == nil || tabID == "" { | |
| 516 | + | return false | |
| 517 | + | } | |
| 518 | + | if a.tabs.Find(tabID) == nil { | |
| 519 | + | return false | |
| 520 | + | } | |
| 521 | + | if a.windowForTab[tabID] != bw { | |
| 522 | + | return false | |
| 523 | + | } | |
| 524 | + | return true | |
| 525 | + | } | |
| 526 | + | ||
| 514 | 527 | func (a *App) tabCountForBrowserWindow(bw *browserWindow) int { | |
| 515 | 528 | if a.tabs == nil || bw == nil { | |
| 516 | 529 | return 0 | |
| @@ -2168,10 +2181,16 @@ func (a *App) initTabCoordinator(ctx context.Context) { | |||
| 2168 | 2181 | }) | |
| 2169 | 2182 | // Wire per-window previous active tab ID provider for scoped Alt+Tab switching | |
| 2170 | 2183 | a.tabCoord.SetPreviousActiveTabIDProvider(func(mainWindow *window.MainWindow) entity.TabID { | |
| 2171 | - | if bw := a.browserWindowForMainWindow(mainWindow); bw != nil { | |
| 2172 | - | return bw.prevActiveTabID | |
| 2184 | + | bw := a.browserWindowForMainWindow(mainWindow) | |
| 2185 | + | if bw == nil { | |
| 2186 | + | return "" | |
| 2173 | 2187 | } | |
| 2174 | - | return "" | |
| 2188 | + | prevID := bw.prevActiveTabID | |
| 2189 | + | if !a.browserWindowHasLiveTab(bw, prevID) { | |
| 2190 | + | bw.prevActiveTabID = "" | |
| 2191 | + | return "" | |
| 2192 | + | } | |
| 2193 | + | return prevID | |
| 2175 | 2194 | }) | |
| 2176 | 2195 | a.tabCoord.SetOnCurrentWindowEmpty(func(ctx context.Context, mainWindow *window.MainWindow) { | |
| 2177 | 2196 | bw := a.browserWindowForMainWindow(mainWindow) | |
| @@ -511,6 +511,19 @@ func (a *App) browserWindowForTab(tabID entity.TabID) *browserWindow { | |||||
| 511 | return a.browserWindowForMainWindow(a.mainWindow) | 511 | return a.browserWindowForMainWindow(a.mainWindow) | ||
| 512 | } | 512 | } | ||
| 513 | 513 | ||||
| 514 | + | func (a *App) browserWindowHasLiveTab(bw *browserWindow, tabID entity.TabID) bool { | |||
| 515 | + | if a == nil || a.tabs == nil || bw == nil || tabID == "" { | |||
| 516 | + | return false | |||
| 517 | + | } | |||
| 518 | + | if a.tabs.Find(tabID) == nil { | |||
| 519 | + | return false | |||
| 520 | + | } | |||
| 521 | + | if a.windowForTab[tabID] != bw { | |||
| 522 | + | return false | |||
| 523 | + | } | |||
| 524 | + | return true | |||
| 525 | + | } | |||
| 526 | + | ||||
| 514 | func (a *App) tabCountForBrowserWindow(bw *browserWindow) int { | 527 | func (a *App) tabCountForBrowserWindow(bw *browserWindow) int { | ||
| 515 | if a.tabs == nil || bw == nil { | 528 | if a.tabs == nil || bw == nil { | ||
| 516 | return 0 | 529 | return 0 | ||
| @@ -2168,10 +2181,16 @@ func (a *App) initTabCoordinator(ctx context.Context) { | |||||
| 2168 | }) | 2181 | }) | ||
| 2169 | // Wire per-window previous active tab ID provider for scoped Alt+Tab switching | 2182 | // Wire per-window previous active tab ID provider for scoped Alt+Tab switching | ||
| 2170 | a.tabCoord.SetPreviousActiveTabIDProvider(func(mainWindow *window.MainWindow) entity.TabID { | 2183 | a.tabCoord.SetPreviousActiveTabIDProvider(func(mainWindow *window.MainWindow) entity.TabID { | ||
| 2171 | - | if bw := a.browserWindowForMainWindow(mainWindow); bw != nil { | 2184 | + | bw := a.browserWindowForMainWindow(mainWindow) |
| 2172 | - | return bw.prevActiveTabID | 2185 | + | if bw == nil { |
| 2186 | + | return "" | |||
| 2173 | } | 2187 | } | ||
| 2174 | - | return "" | 2188 | + | prevID := bw.prevActiveTabID |
| 2189 | + | if !a.browserWindowHasLiveTab(bw, prevID) { | |||
| 2190 | + | bw.prevActiveTabID = "" | |||
| 2191 | + | return "" | |||
| 2192 | + | } | |||
| 2193 | + | return prevID | |||
| 2175 | }) | 2194 | }) | ||
| 2176 | a.tabCoord.SetOnCurrentWindowEmpty(func(ctx context.Context, mainWindow *window.MainWindow) { | 2195 | a.tabCoord.SetOnCurrentWindowEmpty(func(ctx context.Context, mainWindow *window.MainWindow) { | ||
| 2177 | bw := a.browserWindowForMainWindow(mainWindow) | 2196 | bw := a.browserWindowForMainWindow(mainWindow) | ||