diff options
| author | Pitchfork-and-Torch <Pitchfork-and-Torch@users.noreply.github.com> | 2026-07-09 21:11:52 -0400 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-10 15:06:54 +0300 |
| commit | 4f7fcc48d1f760ab6057d0964f009c05b753456a (patch) | |
| tree | ee617c2d12d4c33c2c63a6a8048ab9e80a11d225 /src | |
| parent | c8850a2e3e284033142db0f8117fa5998c68bd59 (diff) | |
fix: follow foreground cwd for new terminals
refs #1245
Diffstat (limited to 'src')
| -rw-r--r-- | src/app/api/layouts.rs | 9 | ||||
| -rw-r--r-- | src/app/api/panes.rs | 2 | ||||
| -rw-r--r-- | src/app/creation.rs | 27 | ||||
| -rw-r--r-- | src/app/input/mod.rs | 3 | ||||
| -rw-r--r-- | src/workspace/tab.rs | 10 |
5 files changed, 31 insertions, 20 deletions
diff --git a/src/app/api/layouts.rs b/src/app/api/layouts.rs index 851221b4..0fdbaba0 100644 --- a/src/app/api/layouts.rs +++ b/src/app/api/layouts.rs @@ -341,11 +341,8 @@ impl App { let follow_cwd = replace_target.and_then(|(_, tab_idx)| { let ws = self.state.workspaces.get(ws_idx)?; let tab = ws.tabs.get(tab_idx)?; - tab.cwd_for_pane( - tab.layout.focused(), - &self.state.terminals, - &self.terminal_runtimes, - ) + let pane_id = tab.layout.focused(); + tab.follow_cwd_for_pane(pane_id, &self.state.terminals, &self.terminal_runtimes) }); self.resolve_new_terminal_cwd( follow_cwd.or_else(|| self.focused_pane_cwd_in_workspace(ws_idx)), @@ -399,7 +396,7 @@ impl App { .cwd .as_ref() .map(PathBuf::from) - .or_else(|| self.cwd_for_pane_in_workspace(ws_idx, target_pane_id)); + .or_else(|| self.follow_cwd_for_pane_in_workspace(ws_idx, target_pane_id)); let extra_env = super::env::normalize_launch_env(pane.env.clone()) .map_err(|(_, message)| message.to_string())?; let direction = match direction { diff --git a/src/app/api/panes.rs b/src/app/api/panes.rs index 9f64dd51..58dbeb19 100644 --- a/src/app/api/panes.rs +++ b/src/app/api/panes.rs @@ -53,7 +53,7 @@ impl App { }; let (rows, cols) = self.state.estimate_pane_size(); let split_cwd = params.cwd.map(std::path::PathBuf::from).or_else(|| { - let follow_cwd = self.cwd_for_pane_in_workspace(ws_idx, target_pane_id); + let follow_cwd = self.follow_cwd_for_pane_in_workspace(ws_idx, target_pane_id); Some(self.resolve_new_terminal_cwd(follow_cwd)) }); let default_shell = self.state.default_shell.clone(); 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<PathBuf> { 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<PathBuf> { 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>) -> 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) => { diff --git a/src/app/input/mod.rs b/src/app/input/mod.rs index e4da8bc9..bcd5da98 100644 --- a/src/app/input/mod.rs +++ b/src/app/input/mod.rs @@ -559,7 +559,8 @@ impl AppState { .and_then(|i| self.workspaces.get(i)) .and_then(|ws| { let tab = ws.active_tab()?; - tab.cwd_for_pane(tab.layout.focused(), &self.terminals, terminal_runtimes) + let pane_id = tab.layout.focused(); + tab.follow_cwd_for_pane(pane_id, &self.terminals, terminal_runtimes) }); let cwd = Some(super::creation::resolve_new_terminal_cwd( &self.new_terminal_cwd, diff --git a/src/workspace/tab.rs b/src/workspace/tab.rs index d1b39ff4..ab9829d0 100644 --- a/src/workspace/tab.rs +++ b/src/workspace/tab.rs @@ -568,4 +568,14 @@ impl Tab { .get(terminal_id) .and_then(|rt| rt.foreground_cwd()) } + + pub fn follow_cwd_for_pane( + &self, + pane_id: PaneId, + terminals: &HashMap<TerminalId, TerminalState>, + terminal_runtimes: &TerminalRuntimeRegistry, + ) -> Option<PathBuf> { + self.foreground_cwd_for_pane(pane_id, terminal_runtimes) + .or_else(|| self.cwd_for_pane(pane_id, terminals, terminal_runtimes)) + } } |
