From 7fd7b7274abd38f0bf88019f1acf70ff03cb1a4e Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:11:02 +0000 Subject: [PATCH] feat: implement copy path of selected item --- helix-term/src/ui/mod.rs | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 0322a6565..e0ab20eb0 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -399,10 +399,27 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result { - create_file_operation_prompt("move:", cx, path, |move_from, move_to| { - let move_to = helix_stdx::path::expand_tilde(PathBuf::from(move_to)); - Ok("".into()) + create_file_operation_prompt("move:", cx, path, |move_from, move_to_str| { + let move_to = helix_stdx::path::expand_tilde(PathBuf::from(move_to_str)); + if move_to.exists() { + // TODO: overwrite prompt + Err(format!("Path {} already exists", move_to.display())) + } else { + fs::rename(move_from, &move_to).map_err(|err| + format!( + "Unable to move {} {} -> {}: {err}", + if move_to_str.ends_with(std::path::MAIN_SEPARATOR) { + "directory" + } else { + "file" + }, + move_from.display(), + move_to.display() + ) + )?; + Ok("".into()) + } }) }, // delete @@ -450,10 +467,15 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result { - // TODO - // cx. - // cx.editor.registers - // .unwrap_or(cx.editor.config().default_yank_register) + let register = cx.editor.selected_register.unwrap_or(cx.editor.config().default_yank_register); + let path = helix_stdx::path::get_relative_path(path); + let path = path.to_string_lossy().to_string(); + let message = format!("Yanked {} to register {register}", path); + + match cx.editor.registers.write(register, vec![path]) { + Ok(_) => cx.editor.set_status(message), + Err(err) => cx.editor.set_error(err.to_string()) + }; } });