Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions pkg/wcore/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,36 @@ func getTabPresetMeta() (waveobj.MetaMapType, error) {

// returns tabid
func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, pinned bool, isInitialLaunch bool) (string, error) {
ws, err := GetWorkspace(ctx, workspaceId)
if err != nil {
return "", fmt.Errorf("workspace %s not found: %w", workspaceId, err)
}

if tabName == "" {
ws, err := GetWorkspace(ctx, workspaceId)
if err != nil {
return "", fmt.Errorf("workspace %s not found: %w", workspaceId, err)
}
tabName = "T" + fmt.Sprint(len(ws.TabIds)+len(ws.PinnedTabIds)+1)
}

// Try to inherit cwd from the active tab
var inheritedMeta waveobj.MetaMapType
if ws.ActiveTabId != "" && !isInitialLaunch {
activeTab, _ := wstore.DBGet[*waveobj.Tab](ctx, ws.ActiveTabId)
if activeTab != nil && len(activeTab.BlockIds) > 0 {
// Get the first block from the active tab
firstBlock, _ := wstore.DBGet[*waveobj.Block](ctx, activeTab.BlockIds[0])
if firstBlock != nil {
meta := waveobj.GetMeta(firstBlock)
if cwd, ok := meta[waveobj.MetaKey_CmdCwd].(string); ok && cwd != "" {
// Inherit the cwd for the new tab
inheritedMeta = waveobj.MetaMapType{
waveobj.MetaKey_CmdCwd: cwd,
}
}
}
}
}

// The initial tab for the initial launch should be pinned
tab, err := createTabObj(ctx, workspaceId, tabName, pinned || isInitialLaunch, nil)
tab, err := createTabObj(ctx, workspaceId, tabName, pinned || isInitialLaunch, inheritedMeta)
if err != nil {
return "", fmt.Errorf("error creating tab: %w", err)
}
Expand All @@ -221,7 +241,17 @@ func CreateTab(ctx context.Context, workspaceId string, tabName string, activate

// No need to apply an initial layout for the initial launch, since the starter layout will get applied after onboarding modal dismissal
if !isInitialLaunch {
err = ApplyPortableLayout(ctx, tab.OID, GetNewTabLayout(), true)
newTabLayout := GetNewTabLayout()
// Merge inherited cwd into the terminal block's meta
if len(inheritedMeta) > 0 && len(newTabLayout) > 0 {
if newTabLayout[0].BlockDef.Meta == nil {
newTabLayout[0].BlockDef.Meta = make(waveobj.MetaMapType)
}
for k, v := range inheritedMeta {
newTabLayout[0].BlockDef.Meta[k] = v
}
}
err = ApplyPortableLayout(ctx, tab.OID, newTabLayout, true)
if err != nil {
return tab.OID, fmt.Errorf("error applying new tab layout: %w", err)
}
Expand Down