mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
setting of active tab improvements (#166)
This commit is contained in:
parent
4df8e16a53
commit
3ff03f7b34
@ -52,26 +52,37 @@ func (svc *WindowService) CloseTab(ctx context.Context, uiContext wstore.UIConte
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error getting tab: %w", err)
|
return nil, fmt.Errorf("error getting tab: %w", err)
|
||||||
}
|
}
|
||||||
|
ws, err := wstore.DBMustGet[*wstore.Workspace](ctx, window.WorkspaceId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting workspace: %w", err)
|
||||||
|
}
|
||||||
|
tabIndex := -1
|
||||||
|
for i, id := range ws.TabIds {
|
||||||
|
if id == tabId {
|
||||||
|
tabIndex = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, blockId := range tab.BlockIds {
|
for _, blockId := range tab.BlockIds {
|
||||||
blockcontroller.StopBlockController(blockId)
|
blockcontroller.StopBlockController(blockId)
|
||||||
}
|
}
|
||||||
err = wstore.DeleteTab(ctx, window.WorkspaceId, tabId)
|
if err := wstore.DeleteTab(ctx, window.WorkspaceId, tabId); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error closing tab: %w", err)
|
return nil, fmt.Errorf("error closing tab: %w", err)
|
||||||
}
|
}
|
||||||
if window.ActiveTabId == tabId {
|
if window.ActiveTabId == tabId && tabIndex != -1 {
|
||||||
ws, err := wstore.DBMustGet[*wstore.Workspace](ctx, window.WorkspaceId)
|
if len(ws.TabIds) == 1 {
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error getting workspace: %w", err)
|
|
||||||
}
|
|
||||||
if len(ws.TabIds) > 0 {
|
|
||||||
newActiveTabId := ws.TabIds[0]
|
|
||||||
wstore.SetActiveTab(ctx, uiContext.WindowId, newActiveTabId)
|
|
||||||
} else {
|
|
||||||
eventbus.SendEventToElectron(eventbus.WSEventType{
|
eventbus.SendEventToElectron(eventbus.WSEventType{
|
||||||
EventType: eventbus.WSEvent_ElectronCloseWindow,
|
EventType: eventbus.WSEvent_ElectronCloseWindow,
|
||||||
Data: uiContext.WindowId,
|
Data: uiContext.WindowId,
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
if tabIndex < len(ws.TabIds)-1 {
|
||||||
|
newActiveTabId := ws.TabIds[tabIndex+1]
|
||||||
|
wstore.SetActiveTab(ctx, uiContext.WindowId, newActiveTabId)
|
||||||
|
} else {
|
||||||
|
newActiveTabId := ws.TabIds[tabIndex-1]
|
||||||
|
wstore.SetActiveTab(ctx, uiContext.WindowId, newActiveTabId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return wstore.ContextGetUpdatesRtn(ctx), nil
|
return wstore.ContextGetUpdatesRtn(ctx), nil
|
||||||
|
Loading…
Reference in New Issue
Block a user