list editor: catch out of bounds in ListEditor::get_item()

This commit is contained in:
Michael Sippel 2021-11-07 08:50:36 +01:00
parent 7fdc0bf272
commit 2fd209c502
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 8 additions and 2 deletions

View file

@ -698,7 +698,11 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static,
pub fn get_item(&self) -> Option<Arc<RwLock<ItemEditor>>> { pub fn get_item(&self) -> Option<Arc<RwLock<ItemEditor>>> {
if let Some(idx) = self.cursor.get().idx { if let Some(idx) = self.cursor.get().idx {
Some(self.data.get(idx)) if idx < self.data.len() {
Some(self.data.get(idx))
} else {
None
}
} else { } else {
None None
} }

View file

@ -162,7 +162,9 @@ async fn main() {
process_list_editor.goto_end(); process_list_editor.goto_end();
} }
TerminalEvent::Input(Event::Key(Key::Char('\n'))) => { TerminalEvent::Input(Event::Key(Key::Char('\n'))) => {
process_list_editor.get_item().unwrap().write().unwrap().launch_pty2(); if let Some(launcher) = process_list_editor.get_item() {
launcher.write().unwrap().launch_pty2();
}
} }
ev => { ev => {