Skip to content

Commit a21f43c

Browse files
Steven Voclaude
authored andcommitted
New tabs inherit working directory from active tab
When creating a new tab (Cmd+T), it now starts in the same directory as the currently active tab, instead of always defaulting to home. ## Changes - Extract cmd:cwd from active tab's first block - Pass inherited cwd to new tab's terminal block via metadata - Only applies to user-created tabs (not initial launch) - Falls back to home directory if no cwd found ## Benefits - More intuitive workflow - stay in your project directory - Reduces need to cd after creating new tabs - Maintains context across tabs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent fbb0c4d commit a21f43c

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

pkg/wcore/workspace.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,36 @@ func getTabPresetMeta() (waveobj.MetaMapType, error) {
199199

200200
// returns tabid
201201
func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, pinned bool, isInitialLaunch bool) (string, error) {
202+
ws, err := GetWorkspace(ctx, workspaceId)
203+
if err != nil {
204+
return "", fmt.Errorf("workspace %s not found: %w", workspaceId, err)
205+
}
206+
202207
if tabName == "" {
203-
ws, err := GetWorkspace(ctx, workspaceId)
204-
if err != nil {
205-
return "", fmt.Errorf("workspace %s not found: %w", workspaceId, err)
206-
}
207208
tabName = "T" + fmt.Sprint(len(ws.TabIds)+len(ws.PinnedTabIds)+1)
208209
}
209210

211+
// Try to inherit cwd from the active tab
212+
var inheritedMeta waveobj.MetaMapType
213+
if ws.ActiveTabId != "" && !isInitialLaunch {
214+
activeTab, _ := wstore.DBGet[*waveobj.Tab](ctx, ws.ActiveTabId)
215+
if activeTab != nil && len(activeTab.BlockIds) > 0 {
216+
// Get the first block from the active tab
217+
firstBlock, _ := wstore.DBGet[*waveobj.Block](ctx, activeTab.BlockIds[0])
218+
if firstBlock != nil {
219+
meta := waveobj.GetMeta(firstBlock)
220+
if cwd, ok := meta[waveobj.MetaKey_CmdCwd].(string); ok && cwd != "" {
221+
// Inherit the cwd for the new tab
222+
inheritedMeta = waveobj.MetaMapType{
223+
waveobj.MetaKey_CmdCwd: cwd,
224+
}
225+
}
226+
}
227+
}
228+
}
229+
210230
// The initial tab for the initial launch should be pinned
211-
tab, err := createTabObj(ctx, workspaceId, tabName, pinned || isInitialLaunch, nil)
231+
tab, err := createTabObj(ctx, workspaceId, tabName, pinned || isInitialLaunch, inheritedMeta)
212232
if err != nil {
213233
return "", fmt.Errorf("error creating tab: %w", err)
214234
}
@@ -221,7 +241,17 @@ func CreateTab(ctx context.Context, workspaceId string, tabName string, activate
221241

222242
// No need to apply an initial layout for the initial launch, since the starter layout will get applied after onboarding modal dismissal
223243
if !isInitialLaunch {
224-
err = ApplyPortableLayout(ctx, tab.OID, GetNewTabLayout(), true)
244+
newTabLayout := GetNewTabLayout()
245+
// Merge inherited cwd into the terminal block's meta
246+
if len(inheritedMeta) > 0 && len(newTabLayout) > 0 {
247+
if newTabLayout[0].BlockDef.Meta == nil {
248+
newTabLayout[0].BlockDef.Meta = make(waveobj.MetaMapType)
249+
}
250+
for k, v := range inheritedMeta {
251+
newTabLayout[0].BlockDef.Meta[k] = v
252+
}
253+
}
254+
err = ApplyPortableLayout(ctx, tab.OID, newTabLayout, true)
225255
if err != nil {
226256
return tab.OID, fmt.Errorf("error applying new tab layout: %w", err)
227257
}

0 commit comments

Comments
 (0)