fix(screen): crash in intermediate no-tabs state (#1272)
* fix(screen): log error instead of crashing in intermediate state with no active tabs * style(fmt): rustfmt
This commit is contained in:
parent
be02f99652
commit
b5cb5474bb
2 changed files with 27 additions and 19 deletions
|
|
@ -42,9 +42,13 @@ impl ZellijPlugin for State {
|
||||||
match event {
|
match event {
|
||||||
Event::ModeUpdate(mode_info) => self.mode_info = mode_info,
|
Event::ModeUpdate(mode_info) => self.mode_info = mode_info,
|
||||||
Event::TabUpdate(tabs) => {
|
Event::TabUpdate(tabs) => {
|
||||||
// tabs are indexed starting from 1 so we need to add 1
|
if let Some(active_tab_index) = tabs.iter().position(|t| t.active) {
|
||||||
self.active_tab_idx = tabs.iter().position(|t| t.active).unwrap() + 1;
|
// tabs are indexed starting from 1 so we need to add 1
|
||||||
self.tabs = tabs;
|
self.active_tab_idx = active_tab_index + 1;
|
||||||
|
self.tabs = tabs;
|
||||||
|
} else {
|
||||||
|
eprintln!("Could not find active tab.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Event::Mouse(me) => match me {
|
Event::Mouse(me) => match me {
|
||||||
Mouse::LeftClick(_, col) => {
|
Mouse::LeftClick(_, col) => {
|
||||||
|
|
@ -59,7 +63,9 @@ impl ZellijPlugin for State {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
_ => unimplemented!(), // FIXME: This should be unreachable, but this could be cleaner
|
_ => {
|
||||||
|
eprintln!("Got unrecognized event: {:?}", event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -255,27 +255,29 @@ impl Screen {
|
||||||
&mut self,
|
&mut self,
|
||||||
client_ids_and_mode_infos: Vec<(ClientId, ModeInfo)>,
|
client_ids_and_mode_infos: Vec<(ClientId, ModeInfo)>,
|
||||||
) {
|
) {
|
||||||
// this will panic if there are no more tabs (ie. if self.tabs.is_empty() == true)
|
if self.tabs.is_empty() {
|
||||||
|
log::error!(
|
||||||
|
"No tabs left, cannot move clients: {:?} from closed tab",
|
||||||
|
client_ids_and_mode_infos
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let first_tab_index = *self.tabs.keys().next().unwrap();
|
||||||
for (client_id, client_mode_info) in client_ids_and_mode_infos {
|
for (client_id, client_mode_info) in client_ids_and_mode_infos {
|
||||||
let client_tab_history = self.tab_history.entry(client_id).or_insert_with(Vec::new);
|
let client_tab_history = self.tab_history.entry(client_id).or_insert_with(Vec::new);
|
||||||
match client_tab_history.pop() {
|
if let Some(client_previous_tab) = client_tab_history.pop() {
|
||||||
Some(client_previous_tab) => {
|
if let Some(client_active_tab) = self.tabs.get_mut(&client_previous_tab) {
|
||||||
self.active_tab_indices
|
self.active_tab_indices
|
||||||
.insert(client_id, client_previous_tab);
|
.insert(client_id, client_previous_tab);
|
||||||
self.tabs
|
client_active_tab.add_client(client_id, Some(client_mode_info));
|
||||||
.get_mut(&client_previous_tab)
|
continue;
|
||||||
.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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.active_tab_indices.insert(client_id, first_tab_index);
|
||||||
|
self.tabs
|
||||||
|
.get_mut(&first_tab_index)
|
||||||
|
.unwrap()
|
||||||
|
.add_client(client_id, Some(client_mode_info));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn move_clients_between_tabs(
|
fn move_clients_between_tabs(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue