Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep tab position when closing tabs #18168

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions crates/workspace/src/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -3315,7 +3311,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);
Expand All @@ -3326,15 +3322,15 @@ 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)
})
.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)
Expand Down
Loading