diff options
| author | akbash <akbash@herdr.dev> | 2026-08-25 23:44:56 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-25 23:44:56 +0300 |
| commit | d79fd746a96ddb5642939c9727baefce642d78e6 (patch) | |
| tree | f6ca7416b082168db6607952d5fb6672f5173826 /src/app/actions.rs | |
| parent | da5357d23f8450d4609f72d079876d7d439ef5a0 (diff) | |
fix: require explicit workspace group close (#3206)
refs #2874
Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com>
Diffstat (limited to 'src/app/actions.rs')
| -rw-r--r-- | src/app/actions.rs | 67 |
1 files changed, 37 insertions, 30 deletions
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::<Vec<_>>() - }) - .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<usize> { 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::<Vec<_>>() }) + .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<usize> { + 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)] |
