Keep tab position when closing tabs (#18168)
- Closes #18036 Release Notes: - N/A
This commit is contained in:
parent
0ee1d7ab26
commit
fd94c2b3fd
1 changed files with 10 additions and 14 deletions
|
@ -1407,17 +1407,13 @@ impl Pane {
|
||||||
self.pinned_tab_count -= 1;
|
self.pinned_tab_count -= 1;
|
||||||
}
|
}
|
||||||
if item_index == self.active_item_index {
|
if item_index == self.active_item_index {
|
||||||
let index_to_activate = self
|
self.activation_history.pop();
|
||||||
.activation_history
|
|
||||||
.pop()
|
let index_to_activate = if item_index + 1 < self.items.len() {
|
||||||
.and_then(|last_activated_item| {
|
item_index + 1
|
||||||
self.items.iter().enumerate().find_map(|(index, item)| {
|
} else {
|
||||||
(item.item_id() == last_activated_item.entity_id).then_some(index)
|
item_index.saturating_sub(1)
|
||||||
})
|
};
|
||||||
})
|
|
||||||
// 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));
|
|
||||||
|
|
||||||
let should_activate = activate_pane || self.has_focus(cx);
|
let should_activate = activate_pane || self.has_focus(cx);
|
||||||
if self.items.len() == 1 && should_activate {
|
if self.items.len() == 1 && should_activate {
|
||||||
|
@ -3320,7 +3316,7 @@ mod tests {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.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));
|
pane.update(cx, |pane, cx| pane.activate_item(3, false, false, cx));
|
||||||
assert_item_labels(&pane, ["A", "B", "C", "D*"], cx);
|
assert_item_labels(&pane, ["A", "B", "C", "D*"], cx);
|
||||||
|
@ -3331,7 +3327,7 @@ mod tests {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_item_labels(&pane, ["A", "B*", "C"], cx);
|
assert_item_labels(&pane, ["A", "B", "C*"], cx);
|
||||||
|
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
pane.close_active_item(&CloseActiveItem { save_intent: None }, cx)
|
pane.close_active_item(&CloseActiveItem { save_intent: None }, cx)
|
||||||
|
@ -3339,7 +3335,7 @@ mod tests {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_item_labels(&pane, ["A", "C*"], cx);
|
assert_item_labels(&pane, ["A", "B*"], cx);
|
||||||
|
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
pane.close_active_item(&CloseActiveItem { save_intent: None }, cx)
|
pane.close_active_item(&CloseActiveItem { save_intent: None }, cx)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue