From d79fd746a96ddb5642939c9727baefce642d78e6 Mon Sep 17 00:00:00 2001 From: akbash Date: Tue, 25 Aug 2026 23:44:56 +0300 Subject: fix: require explicit workspace group close (#3206) refs #2874 Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com> --- src/app/actions.rs | 67 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 30 deletions(-) (limited to 'src/app/actions.rs') diff --git a/src/app/actions.rs b/src/app/actions.rs index e3fc2639..07f7278b 100644 --- a/src/app/actions.rs +++ b/src/app/actions.rs @@ -1677,24 +1677,7 @@ impl AppState { self.selection = None; self.selection_autoscroll = None; self.mark_session_dirty(); - let close_indices = self - .workspaces - .get(self.selected) - .and_then(|ws| ws.worktree_space()) - .filter(|space| !space.is_linked_worktree) - .map(|space| { - self.workspaces - .iter() - .enumerate() - .filter_map(|(idx, ws)| { - ws.worktree_space() - .is_some_and(|member| member.key == space.key) - .then_some(idx) - }) - .collect::>() - }) - .filter(|indices| indices.len() >= 2) - .unwrap_or_else(|| vec![self.selected]); + let close_indices = self.workspace_close_indices(self.selected); let mut terminal_ids = Vec::new(); let mut pane_ids = Vec::new(); @@ -1984,31 +1967,55 @@ impl AppState { self.apply_pane_zoom(ws_idx, pane_id, PaneZoomCommand::Toggle); } - pub(crate) fn workspace_close_would_close_worktree_group(&self, ws_idx: usize) -> bool { + pub(crate) fn workspace_close_indices(&self, ws_idx: usize) -> Vec { self.workspaces .get(ws_idx) .and_then(|ws| ws.worktree_space()) .filter(|space| !space.is_linked_worktree) - .is_some_and(|space| { + .map(|space| { self.workspaces .iter() - .filter(|ws| { + .enumerate() + .filter_map(|(idx, ws)| { ws.worktree_space() .is_some_and(|member| member.key == space.key) + .then_some(idx) }) - .count() - >= 2 + .collect::>() }) + .filter(|indices| indices.len() >= 2) + .unwrap_or_else(|| vec![ws_idx]) + } + + pub(crate) fn workspace_close_would_close_worktree_group(&self, ws_idx: usize) -> bool { + self.workspace_close_indices(ws_idx).len() >= 2 + } + + pub(crate) fn begin_workspace_close_confirmation(&mut self, ws_idx: usize) -> bool { + let Some(workspace_id) = self + .workspaces + .get(ws_idx) + .map(|workspace| workspace.id.clone()) + else { + return false; + }; + self.selected = ws_idx; + self.confirm_close_workspace_id = Some(workspace_id); + self.mode = Mode::ConfirmClose; + true + } + + pub(crate) fn take_confirmed_workspace_close_index(&mut self) -> Option { + let workspace_id = self.confirm_close_workspace_id.take()?; + self.workspaces + .iter() + .position(|workspace| workspace.id == workspace_id) } pub(crate) fn confirm_implicit_worktree_group_close(&mut self, ws_idx: usize) -> bool { - if self.confirm_close && self.workspace_close_would_close_worktree_group(ws_idx) { - self.selected = ws_idx; - self.mode = Mode::ConfirmClose; - true - } else { - false - } + self.confirm_close + && self.workspace_close_would_close_worktree_group(ws_idx) + && self.begin_workspace_close_confirmation(ws_idx) } #[cfg(test)] -- cgit v1.2.3