aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/actions.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/app/actions.rs b/src/app/actions.rs
index 10d28054..c23c219c 100644
--- a/src/app/actions.rs
+++ b/src/app/actions.rs
@@ -1697,6 +1697,10 @@ impl AppState {
crate::logging::workspace_closed(&workspace_id);
}
}
+ let active_workspace_id = self
+ .active
+ .and_then(|idx| self.workspaces.get(idx))
+ .map(|ws| ws.id.clone());
self.remove_plugin_pane_records(pane_ids);
for idx in close_indices.iter().rev() {
self.workspaces.remove(*idx);
@@ -1709,6 +1713,12 @@ impl AppState {
self.tab_scroll = 0;
self.tab_scroll_follow_active = true;
} else {
+ // Keep focus on the previously focused workspace
+ if let Some(id) = active_workspace_id {
+ if let Some(idx) = self.workspaces.iter().position(|ws| ws.id == id) {
+ self.selected = idx;
+ }
+ }
if self.selected >= self.workspaces.len() {
self.selected = self.workspaces.len() - 1;
}
@@ -4620,6 +4630,22 @@ mod tests {
}
#[test]
+ fn close_non_focused_workspace_keeps_focus() {
+ let mut state = app_with_workspaces(&["a", "b", "c"]);
+ state.selected = 1;
+ state.active = Some(0);
+
+ state.close_selected_workspace();
+
+ assert_eq!(state.workspaces.len(), 2);
+ assert_eq!(state.workspaces[0].display_name(), "a");
+ assert_eq!(state.workspaces[1].display_name(), "c");
+ assert_eq!(state.selected, 0);
+ assert_eq!(state.active, Some(0));
+ state.assert_invariants_for_test();
+ }
+
+ #[test]
fn pane_died_last_pane_removes_workspace() {
let mut state = app_with_workspaces(&["a", "b"]);
let pane_id = *state.workspaces[0].panes.keys().next().unwrap();