From 4f7fcc48d1f760ab6057d0964f009c05b753456a Mon Sep 17 00:00:00 2001 From: Pitchfork-and-Torch Date: Thu, 9 Jul 2026 21:11:52 -0400 Subject: fix: follow foreground cwd for new terminals refs #1245 --- src/app/creation.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/app/creation.rs') diff --git a/src/app/creation.rs b/src/app/creation.rs index 13fc0a8e..734c57aa 100644 --- a/src/app/creation.rs +++ b/src/app/creation.rs @@ -38,21 +38,23 @@ impl App { .resolved_identity_cwd_from(&self.state.terminals, &self.terminal_runtimes) } - pub(super) fn cwd_for_pane_in_workspace( + pub(super) fn follow_cwd_for_pane_in_workspace( &self, ws_idx: usize, pane_id: crate::layout::PaneId, ) -> Option { let ws = self.state.workspaces.get(ws_idx)?; let tab_idx = ws.find_tab_index_for_pane(pane_id)?; - ws.tabs - .get(tab_idx)? - .cwd_for_pane(pane_id, &self.state.terminals, &self.terminal_runtimes) + ws.tabs.get(tab_idx)?.follow_cwd_for_pane( + pane_id, + &self.state.terminals, + &self.terminal_runtimes, + ) } pub(super) fn focused_pane_cwd_in_workspace(&self, ws_idx: usize) -> Option { let pane_id = self.state.workspaces.get(ws_idx)?.focused_pane_id()?; - self.cwd_for_pane_in_workspace(ws_idx, pane_id) + self.follow_cwd_for_pane_in_workspace(ws_idx, pane_id) } pub(super) fn resolve_new_terminal_cwd(&self, follow_cwd: Option) -> PathBuf { @@ -77,9 +79,10 @@ impl App { /// Create a workspace with a real PTY (needs event_tx). #[cfg(test)] pub(crate) fn create_workspace(&mut self) { - let follow_cwd = self - .workspace_creation_source() - .and_then(|ws_idx| self.seed_cwd_from_workspace(ws_idx)); + let follow_cwd = self.workspace_creation_source().and_then(|ws_idx| { + self.focused_pane_cwd_in_workspace(ws_idx) + .or_else(|| self.seed_cwd_from_workspace(ws_idx)) + }); let initial_cwd = self.resolve_new_terminal_cwd(follow_cwd); if let Err(e) = self.create_workspace_with_events(initial_cwd, true) { error!(err = %e, "failed to create workspace"); @@ -91,10 +94,10 @@ impl App { pub(crate) fn create_tab(&mut self) { let custom_name = self.state.requested_new_tab_name.take(); let active_before = self.state.active; - let follow_cwd = self - .state - .active - .and_then(|ws_idx| self.seed_cwd_from_workspace(ws_idx)); + let follow_cwd = self.state.active.and_then(|ws_idx| { + self.focused_pane_cwd_in_workspace(ws_idx) + .or_else(|| self.seed_cwd_from_workspace(ws_idx)) + }); let initial_cwd = self.resolve_new_terminal_cwd(follow_cwd); match self.create_tab_with_options(initial_cwd, true) { Ok(created_idx) => { -- cgit v1.2.3