mirror of https://github.com/helix-editor/helix
refactor: extract into a function
parent
f193705ca7
commit
67ca955baa
|
@ -396,6 +396,16 @@ fn refresh_file_explorer(cursor: u32, cx: &mut Context, root: PathBuf) {
|
||||||
cx.jobs.callback(callback);
|
cx.jobs.callback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We don't have access to the file explorer's current directory directly,
|
||||||
|
/// but we can get it by taking any of the children of the explorer
|
||||||
|
/// and obtaining their parents.
|
||||||
|
fn root_from_child(child: &Path) -> PathBuf {
|
||||||
|
child
|
||||||
|
.parent()
|
||||||
|
.map(|p| p.to_path_buf())
|
||||||
|
.unwrap_or(helix_stdx::env::current_working_dir())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn file_explorer(
|
pub fn file_explorer(
|
||||||
cursor: Option<u32>,
|
cursor: Option<u32>,
|
||||||
root: PathBuf,
|
root: PathBuf,
|
||||||
|
@ -471,10 +481,7 @@ pub fn file_explorer(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let root = path
|
let root = root_from_child(path);
|
||||||
.parent()
|
|
||||||
.map(|p| p.to_path_buf())
|
|
||||||
.unwrap_or(helix_stdx::env::current_working_dir());
|
|
||||||
|
|
||||||
if to_create.exists() {
|
if to_create.exists() {
|
||||||
create_confirmation_prompt(
|
create_confirmation_prompt(
|
||||||
|
@ -531,10 +538,7 @@ pub fn file_explorer(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let root = move_from
|
let root = root_from_child(move_from);
|
||||||
.parent()
|
|
||||||
.map(|p| p.to_path_buf())
|
|
||||||
.unwrap_or(helix_stdx::env::current_working_dir());
|
|
||||||
|
|
||||||
if move_to.exists() {
|
if move_to.exists() {
|
||||||
create_confirmation_prompt(
|
create_confirmation_prompt(
|
||||||
|
@ -570,10 +574,7 @@ pub fn file_explorer(
|
||||||
return Some(Err(format!("Path {} does not exist", to_delete.display())));
|
return Some(Err(format!("Path {} does not exist", to_delete.display())));
|
||||||
};
|
};
|
||||||
|
|
||||||
let root = to_delete
|
let root = root_from_child(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 confirmation.ends_with(std::path::MAIN_SEPARATOR) {
|
||||||
if let Err(err) = fs::remove_dir_all(to_delete).map_err(|err| {
|
if let Err(err) = fs::remove_dir_all(to_delete).map_err(|err| {
|
||||||
|
@ -639,10 +640,7 @@ pub fn file_explorer(
|
||||||
)))
|
)))
|
||||||
};
|
};
|
||||||
|
|
||||||
let root = copy_to
|
let root = root_from_child(©_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(std::path::MAIN_SEPARATOR) {
|
if copy_from.is_dir() || copy_to_str.ends_with(std::path::MAIN_SEPARATOR) {
|
||||||
// TODO: support copying directories (recursively)?. This isn't built-in to the standard library
|
// TODO: support copying directories (recursively)?. This isn't built-in to the standard library
|
||||||
|
|
Loading…
Reference in New Issue