From 7be5b8dfc9cb9196ac35cc34ea13e6c1209a9fe0 Mon Sep 17 00:00:00 2001 From: Denis Kolodin Date: Sat, 19 Nov 2022 15:26:47 +0100 Subject: [PATCH] Refactor a picker of the current view --- helix-term/src/commands.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5c50db1d2ce82..6063132d9a100 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2269,22 +2269,18 @@ fn file_picker(cx: &mut Context) { } fn file_picker_in_current_buffer_directory(cx: &mut Context) { - let doc = doc!(cx.editor); - - let doc_dir = match doc + let doc_dir = doc!(cx.editor) .path() - .and_then(|path| path.parent().map(|path| path.to_path_buf())) - { - Some(path) => path, - None => { - cx.editor.set_error("current buffer has no path or parent"); - return; - } - }; - - let picker = ui::file_picker(doc_dir, &cx.editor.config()); - cx.push_layer(Box::new(overlayed(picker))); + .and_then(|path| path.parent()) + .map(Path::to_path_buf); + if let Some(path) = doc_dir { + let picker = ui::file_picker(path, &cx.editor.config()); + cx.push_layer(Box::new(overlayed(picker))); + } else { + cx.editor.set_error("current buffer has no path or parent"); + } } + fn file_picker_in_current_directory(cx: &mut Context) { let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("./")); let picker = ui::file_picker(cwd, &cx.editor.config());