feat: implement copy path of selected item
This commit is contained in:
parent
b3d0f16276
commit
7fd7b7274a
1 changed files with 29 additions and 7 deletions
|
@ -399,10 +399,27 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std
|
||||||
},
|
},
|
||||||
// move
|
// move
|
||||||
alt!('m') => {
|
alt!('m') => {
|
||||||
create_file_operation_prompt("move:", cx, path, |move_from, move_to| {
|
create_file_operation_prompt("move:", cx, path, |move_from, move_to_str| {
|
||||||
let move_to = helix_stdx::path::expand_tilde(PathBuf::from(move_to));
|
let move_to = helix_stdx::path::expand_tilde(PathBuf::from(move_to_str));
|
||||||
Ok("".into())
|
|
||||||
|
|
||||||
|
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
|
// delete
|
||||||
|
@ -450,10 +467,15 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std
|
||||||
},
|
},
|
||||||
// copy path
|
// copy path
|
||||||
alt!('y') => {
|
alt!('y') => {
|
||||||
// TODO
|
let register = cx.editor.selected_register.unwrap_or(cx.editor.config().default_yank_register);
|
||||||
// cx.
|
let path = helix_stdx::path::get_relative_path(path);
|
||||||
// cx.editor.registers
|
let path = path.to_string_lossy().to_string();
|
||||||
// .unwrap_or(cx.editor.config().default_yank_register)
|
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())
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue