pty editor: more resilient handling of results in join functions

This commit is contained in:
Michael Sippel 2023-03-02 02:42:30 +01:00
parent fb20fb94e7
commit f1eedad3fe
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -192,7 +192,8 @@ impl PTYListEditor {
{ {
let prev_editor = e.data.get_mut(idx as usize-1); let prev_editor = e.data.get_mut(idx as usize-1);
let prev_editor = prev_editor.editor.clone(); let prev_editor = prev_editor.editor.clone();
let prev_editor = prev_editor.unwrap().downcast::<RwLock<ListEditor>>().unwrap(); if let Some(prev_editor) = prev_editor {
if let Ok(prev_editor) = prev_editor.downcast::<RwLock<ListEditor>>() {
let mut prev_editor = prev_editor.write().unwrap(); let mut prev_editor = prev_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap(); let cur_editor = item.editor.clone().unwrap();
@ -200,7 +201,6 @@ impl PTYListEditor {
let cur_editor = cur_editor.write().unwrap(); let cur_editor = cur_editor.write().unwrap();
prev_editor.join(&cur_editor); prev_editor.join(&cur_editor);
}
e.cursor.set( e.cursor.set(
ListCursor { ListCursor {
@ -208,21 +208,27 @@ impl PTYListEditor {
} }
); );
}
}
}
e.data.remove(idx as usize); e.data.remove(idx as usize);
} }
fn join_nexd(e: &mut ListEditor, next_idx: usize, item: &NestedNode) { fn join_nexd(e: &mut ListEditor, next_idx: usize, item: &NestedNode) {
{ {
let next_editor = e.data.get_mut(next_idx).editor.clone(); let next_editor = e.data.get_mut(next_idx).editor.clone();
let next_editor = next_editor.unwrap().downcast::<RwLock<ListEditor>>().unwrap(); if let Some(next_editor) = next_editor {
let next_editor = next_editor.write().unwrap(); if let Ok(next_editor) = next_editor.downcast::<RwLock<ListEditor>>() {
let mut next_editor = next_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap(); let cur_editor = item.editor.clone().unwrap();
let cur_editor = cur_editor.downcast::<RwLock<ListEditor>>().unwrap(); let cur_editor = cur_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut cur_editor = cur_editor.write().unwrap(); let mut cur_editor = cur_editor.write().unwrap();
cur_editor.join(&next_editor); cur_editor.join(&next_editor);
} }
}
}
e.data.remove(next_idx); e.data.remove(next_idx);
} }
} }