mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 14:17:02 +00:00
Ensure active_item_index
doesn't go off the end when closing items
This fixes a bug introduced in #538, where closing the current tab would hide all the other tabs, if the current tab was the last one. Also, this commit manually sets the active item index instead of calling `Pane::activate_item`: even though this introduces a little bit of duplication, it prevents us from mistakenly calling `deactivate` on the wrong item. This would happen because `activate_item` looks at `self.active_item_index` to determine which item to deactivate before setting the new one. However, that index is potentially invalid because `::close_items` manipulates the `item_views` vector, so `activate_item` could end up calling `deactivate` on an item view that was not active in the first place.
This commit is contained in:
parent
c7ddb66795
commit
711de5edcb
1 changed files with 4 additions and 2 deletions
|
@ -406,11 +406,13 @@ impl Pane {
|
||||||
});
|
});
|
||||||
|
|
||||||
if self.item_views.is_empty() {
|
if self.item_views.is_empty() {
|
||||||
self.update_active_toolbar(cx);
|
|
||||||
cx.emit(Event::Remove);
|
cx.emit(Event::Remove);
|
||||||
} else {
|
} else {
|
||||||
self.activate_item(new_active_item_index, cx);
|
self.active_item_index = cmp::min(new_active_item_index, self.item_views.len() - 1);
|
||||||
|
self.focus_active_item(cx);
|
||||||
|
self.activate(cx);
|
||||||
}
|
}
|
||||||
|
self.update_active_toolbar(cx);
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue