fix: call onTabCreated before AddTab so window-scoped name is set
TabButton reads tab.Title() immediately when created, so the window-scoped default name must be assigned before TabBar.AddTab().
- commit
- 4ea143081f2cd8820afdb69b8d3f788daaffc955
- author
- brice · · 2026-04-28 07:14 UTC
- parent
- e6ff2cc
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +8 -6
M internal/ui/app.go +1 -1
| @@ -2097,7 +2097,7 @@ func (a *App) initCoordinators(ctx context.Context) { | |||
| 2097 | 2097 | a.setBrowserWindowForTab(tab.ID, bw) | |
| 2098 | 2098 | } | |
| 2099 | 2099 | // Set a window-scoped default title so "Tab N" doesn't use global position. | |
| 2100 | - | // Count tabs already owned by this window (excluding the one just added). | |
| 2100 | + | // Count tabs owned by this window. The new tab was just assigned above. | |
| 2101 | 2101 | windowTabCount := 0 | |
| 2102 | 2102 | for _, owner := range a.windowForTab { | |
| 2103 | 2103 | if owner == bw { | |
| @@ -2097,7 +2097,7 @@ func (a *App) initCoordinators(ctx context.Context) { | |||||
| 2097 | a.setBrowserWindowForTab(tab.ID, bw) | 2097 | a.setBrowserWindowForTab(tab.ID, bw) | ||
| 2098 | } | 2098 | } | ||
| 2099 | // Set a window-scoped default title so "Tab N" doesn't use global position. | 2099 | // Set a window-scoped default title so "Tab N" doesn't use global position. | ||
| 2100 | - | // Count tabs already owned by this window (excluding the one just added). | 2100 | + | // Count tabs owned by this window. The new tab was just assigned above. |
| 2101 | windowTabCount := 0 | 2101 | windowTabCount := 0 | ||
| 2102 | for _, owner := range a.windowForTab { | 2102 | for _, owner := range a.windowForTab { | ||
| 2103 | if owner == bw { | 2103 | if owner == bw { | ||
M internal/ui/coordinator/tab.go +7 -5
| @@ -156,6 +156,13 @@ func (c *TabCoordinator) create(ctx context.Context, initialURL string, activate | |||
| 156 | 156 | c.tabs.SetActive(output.Tab.ID) | |
| 157 | 157 | } | |
| 158 | 158 | ||
| 159 | + | // Notify app before adding the tab to the visible tab bar. | |
| 160 | + | // The app assigns window ownership and the window-scoped default name here, | |
| 161 | + | // and TabBar.AddTab reads tab.Title() immediately when creating the button. | |
| 162 | + | if c.onTabCreated != nil { | |
| 163 | + | c.onTabCreated(ctx, output.Tab) | |
| 164 | + | } | |
| 165 | + | ||
| 159 | 166 | // Update tab bar | |
| 160 | 167 | if c.mainWindow != nil && c.mainWindow.TabBar() != nil { | |
| 161 | 168 | c.mainWindow.TabBar().AddTab(output.Tab) | |
| @@ -167,11 +174,6 @@ func (c *TabCoordinator) create(ctx context.Context, initialURL string, activate | |||
| 167 | 174 | // Update tab bar visibility | |
| 168 | 175 | c.UpdateBarVisibility(ctx) | |
| 169 | 176 | ||
| 170 | - | // Notify app to create workspace view | |
| 171 | - | if c.onTabCreated != nil { | |
| 172 | - | c.onTabCreated(ctx, output.Tab) | |
| 173 | - | } | |
| 174 | - | ||
| 175 | 177 | // Switch to the new tab's workspace view when activation is requested. | |
| 176 | 178 | if activate && c.onTabSwitched != nil { | |
| 177 | 179 | c.onTabSwitched(ctx, output.Tab) | |
| @@ -156,6 +156,13 @@ func (c *TabCoordinator) create(ctx context.Context, initialURL string, activate | |||||
| 156 | c.tabs.SetActive(output.Tab.ID) | 156 | c.tabs.SetActive(output.Tab.ID) | ||
| 157 | } | 157 | } | ||
| 158 | 158 | ||||
| 159 | + | // Notify app before adding the tab to the visible tab bar. | |||
| 160 | + | // The app assigns window ownership and the window-scoped default name here, | |||
| 161 | + | // and TabBar.AddTab reads tab.Title() immediately when creating the button. | |||
| 162 | + | if c.onTabCreated != nil { | |||
| 163 | + | c.onTabCreated(ctx, output.Tab) | |||
| 164 | + | } | |||
| 165 | + | ||||
| 159 | // Update tab bar | 166 | // Update tab bar | ||
| 160 | if c.mainWindow != nil && c.mainWindow.TabBar() != nil { | 167 | if c.mainWindow != nil && c.mainWindow.TabBar() != nil { | ||
| 161 | c.mainWindow.TabBar().AddTab(output.Tab) | 168 | c.mainWindow.TabBar().AddTab(output.Tab) | ||
| @@ -167,11 +174,6 @@ func (c *TabCoordinator) create(ctx context.Context, initialURL string, activate | |||||
| 167 | // Update tab bar visibility | 174 | // Update tab bar visibility | ||
| 168 | c.UpdateBarVisibility(ctx) | 175 | c.UpdateBarVisibility(ctx) | ||
| 169 | 176 | ||||
| 170 | - | // Notify app to create workspace view | |||
| 171 | - | if c.onTabCreated != nil { | |||
| 172 | - | c.onTabCreated(ctx, output.Tab) | |||
| 173 | - | } | |||
| 174 | - | ||||
| 175 | // Switch to the new tab's workspace view when activation is requested. | 177 | // Switch to the new tab's workspace view when activation is requested. | ||
| 176 | if activate && c.onTabSwitched != nil { | 178 | if activate && c.onTabSwitched != nil { | ||
| 177 | c.onTabSwitched(ctx, output.Tab) | 179 | c.onTabSwitched(ctx, output.Tab) | ||