From e6e80e21855a5843da28a0d8d0c080d5c5665caf Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 18 Feb 2025 14:27:11 +0000 Subject: [PATCH] fix: remove unneeded panics --- helix-term/src/ui/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 585898a6c..85db1a112 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -467,7 +467,9 @@ pub fn file_explorer( } }; - let root = path.parent().unwrap().to_path_buf(); + let root = path.parent().map( + |p| p.to_path_buf() + ).unwrap_or(helix_stdx::env::current_working_dir()); if to_create.exists() { create_confirmation_prompt( @@ -518,7 +520,9 @@ pub fn file_explorer( None }; - let root = move_from.parent().unwrap().to_path_buf(); + let root = move_from.parent().map( + |p| p.to_path_buf() + ).unwrap_or(helix_stdx::env::current_working_dir()); if move_to.exists() { create_confirmation_prompt( @@ -552,7 +556,9 @@ pub fn file_explorer( return Some(Err(format!("Path {} does not exist", to_delete.display()))) }; - let root = to_delete.parent().unwrap().to_path_buf(); + let root = to_delete.parent().map( + |p| p.to_path_buf() + ).unwrap_or(helix_stdx::env::current_working_dir()); if confirmation.ends_with(std::path::MAIN_SEPARATOR) { if let Err(err) = fs::remove_dir_all(to_delete).map_err( @@ -608,7 +614,9 @@ pub fn file_explorer( ))) }; - let root = copy_from.parent().unwrap().to_path_buf(); + let root = copy_to.parent().map( + |p| p.to_path_buf() + ).unwrap_or(helix_stdx::env::current_working_dir()); if copy_from.is_dir() || copy_to_str.ends_with('/') { // TODO: support copying directories (recursively)?. This isn't built-in to the standard library