From 403684d4116cc60e2b1b27769b25c1f9b5f25a14 Mon Sep 17 00:00:00 2001 From: 5-pebbles <5-pebble@protonmail.com> Date: Fri, 5 Jul 2024 09:07:07 -0400 Subject: [PATCH] refactor(cmds): cleanup `move_buffer_impl`; --- helix-term/src/commands/typed.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 63403b0bd..7a118d950 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2402,16 +2402,15 @@ fn move_buffer_impl(cx: &mut compositor::Context, path: &str, force: bool) -> an .path() .context("Scratch buffer cannot be moved. Use `:write` instead")? .clone(); - let new_path = path.to_string(); + let new_path = Path::new(path); - if !force && Path::new(&new_path).exists() { - bail!("Destination already exists. Use `:move!` to overwrite"); + if !force && new_path.exists() { + bail!("Destination exists. Use `:move!` to overwrite"); } - if let Err(err) = cx.editor.move_path(&old_path, new_path.as_ref()) { - bail!("Could not move file: {err}"); - } - Ok(()) + cx.editor + .move_path(&old_path, new_path) + .map_err(|err| anyhow!("Failed to move file: {err}")) } fn move_buffer(