Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Keep tab position when closing tabs (#18168)
Patrickfd94c2b3fd5c
diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex 82300690e7d..3e228b7b160 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -1407,17 +1407,13 @@ impl Pane {self.pinned_tab_count -= 1;}if item_index == self.active_item_index {- let index_to_activate = self- .activation_history- .pop()- .and_then(|last_activated_item| {- self.items.iter().enumerate().find_map(|(index, item)| {- (item.item_id() == last_activated_item.entity_id).then_some(index)- })- })- // We didn't have a valid activation history entry, so fallback- // to activating the item to the left- .unwrap_or_else(|| item_index.min(self.items.len()).saturating_sub(1));+ self.activation_history.pop();++ let index_to_activate = if item_index + 1 < self.items.len() {+ item_index + 1+ } else {+ item_index.saturating_sub(1)+ };let should_activate = activate_pane || self.has_focus(cx);if self.items.len() == 1 && should_activate {@@ -3320,7 +3316,7 @@ mod tests {.unwrap().await.unwrap();- assert_item_labels(&pane, ["A", "B*", "C", "D"], cx);+ assert_item_labels(&pane, ["A", "B", "C*", "D"], cx);pane.update(cx, |pane, cx| pane.activate_item(3, false, false, cx));assert_item_labels(&pane, ["A", "B", "C", "D*"], cx);@@ -3331,7 +3327,7 @@ mod tests {.unwrap().await.unwrap();- assert_item_labels(&pane, ["A", "B*", "C"], cx);+ assert_item_labels(&pane, ["A", "B", "C*"], cx);pane.update(cx, |pane, cx| {pane.close_active_item(&CloseActiveItem { save_intent: None }, cx)@@ -3339,7 +3335,7 @@ mod tests {.unwrap().await.unwrap();- assert_item_labels(&pane, ["A", "C*"], cx);+ assert_item_labels(&pane, ["A", "B*"], cx);pane.update(cx, |pane, cx| {pane.close_active_item(&CloseActiveItem { save_intent: None }, cx)