fix(tabs): dont panic when tab history is empty and closing tab (#990)

This commit is contained in:
Aram Drevekenin 2022-01-04 11:07:09 +01:00 committed by GitHub
parent 4496c4d4dc
commit d5fe53ef57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -237,14 +237,27 @@ 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();
self.active_tab_indices
.insert(client_id, client_previous_tab);
self.tabs
.get_mut(&client_previous_tab)
.unwrap()
.add_client(client_id, Some(client_mode_info));
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
.get_mut(&client_previous_tab)
.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(