fix(tabs): dont panic when tab history is empty and closing tab
@@ -237,8 +237,11 @@ impl Screen {
&mut self,
client_ids_and_mode_infos: Vec<(ClientId, ModeInfo)>,
) {
+ // this will panic if there are no more tabs (ie. if self.tabs.is_empty() == true)
for (client_id, client_mode_info) in client_ids_and_mode_infos {
- let client_previous_tab = self.tab_history.get_mut(&client_id).unwrap().pop().unwrap();
+ let client_tab_history = self.tab_history.entry(client_id).or_insert_with(Vec::new);
+ match client_tab_history.pop() {
+ Some(client_previous_tab) => {
self.active_tab_indices
.insert(client_id, client_previous_tab);
self.tabs
@@ -246,6 +249,16 @@ impl Screen {
.unwrap()
.add_client(client_id, Some(client_mode_info));
}
+ None => {
+ let next_tab_index = *self.tabs.keys().next().unwrap();
+ self.active_tab_indices.insert(client_id, next_tab_index);
+ self.tabs
+ .get_mut(&next_tab_index)
+ .unwrap()
+ .add_client(client_id, Some(client_mode_info));
+ }
+ }
+ }
}
fn move_clients_between_tabs(
&mut self,
