From f1eedad3fe7480b8bcb88400fd4a77667af21f51 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Thu, 2 Mar 2023 02:42:30 +0100 Subject: [PATCH] pty editor: more resilient handling of results in join functions --- nested/src/editors/list/pty_editor.rs | 42 +++++++++++++++------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/nested/src/editors/list/pty_editor.rs b/nested/src/editors/list/pty_editor.rs index 2103d4c..056faba 100644 --- a/nested/src/editors/list/pty_editor.rs +++ b/nested/src/editors/list/pty_editor.rs @@ -192,21 +192,25 @@ impl PTYListEditor { { let prev_editor = e.data.get_mut(idx as usize-1); let prev_editor = prev_editor.editor.clone(); - let prev_editor = prev_editor.unwrap().downcast::>().unwrap(); - let mut prev_editor = prev_editor.write().unwrap(); + if let Some(prev_editor) = prev_editor { + if let Ok(prev_editor) = prev_editor.downcast::>() { + let mut prev_editor = prev_editor.write().unwrap(); - let cur_editor = item.editor.clone().unwrap(); - let cur_editor = cur_editor.downcast::>().unwrap(); - let cur_editor = cur_editor.write().unwrap(); + let cur_editor = item.editor.clone().unwrap(); + let cur_editor = cur_editor.downcast::>().unwrap(); + let cur_editor = cur_editor.write().unwrap(); - prev_editor.join(&cur_editor); - } + prev_editor.join(&cur_editor); + + e.cursor.set( + ListCursor { + idx: Some(idx - 1), mode: ListCursorMode::Select + } + ); - e.cursor.set( - ListCursor { - idx: Some(idx - 1), mode: ListCursorMode::Select + } } - ); + } e.data.remove(idx as usize); } @@ -214,14 +218,16 @@ impl PTYListEditor { 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 = next_editor.unwrap().downcast::>().unwrap(); - let next_editor = next_editor.write().unwrap(); + if let Some(next_editor) = next_editor { + if let Ok(next_editor) = next_editor.downcast::>() { + let mut next_editor = next_editor.write().unwrap(); + let cur_editor = item.editor.clone().unwrap(); + let cur_editor = cur_editor.downcast::>().unwrap(); + let mut cur_editor = cur_editor.write().unwrap(); - let cur_editor = item.editor.clone().unwrap(); - let cur_editor = cur_editor.downcast::>().unwrap(); - let mut cur_editor = cur_editor.write().unwrap(); - - cur_editor.join(&next_editor); + cur_editor.join(&next_editor); + } + } } e.data.remove(next_idx); }