refactor: simplify function
This commit is contained in:
parent
eb35b604b5
commit
7fdf2ba92a
1 changed files with 20 additions and 17 deletions
|
@ -382,18 +382,12 @@ fn create_file_operation_prompt(
|
|||
cx.jobs.callback(callback);
|
||||
}
|
||||
|
||||
fn refresh_file_explorer(
|
||||
remove_previous: bool,
|
||||
cursor: Option<u32>,
|
||||
cx: &mut Context,
|
||||
root: PathBuf,
|
||||
) {
|
||||
fn refresh_file_explorer(cursor: u32, cx: &mut Context, root: PathBuf) {
|
||||
let callback = Box::pin(async move {
|
||||
let call: Callback = Callback::EditorCompositor(Box::new(move |editor, compositor| {
|
||||
if remove_previous {
|
||||
compositor.pop();
|
||||
}
|
||||
if let Ok(picker) = file_explorer(cursor, root, editor) {
|
||||
// replace the old file explorer with the new one
|
||||
compositor.pop();
|
||||
if let Ok(picker) = file_explorer(Some(cursor), root, editor) {
|
||||
compositor.push(Box::new(overlay::overlaid(picker)));
|
||||
}
|
||||
}));
|
||||
|
@ -462,7 +456,7 @@ pub fn file_explorer(
|
|||
}) {
|
||||
return Some(Err(err));
|
||||
}
|
||||
refresh_file_explorer(true, Some(cursor), cx, root);
|
||||
refresh_file_explorer(cursor, cx, root);
|
||||
|
||||
Some(Ok(format!("Created directory: {}", to_create.display())))
|
||||
} else {
|
||||
|
@ -471,7 +465,7 @@ pub fn file_explorer(
|
|||
}) {
|
||||
return Some(Err(err));
|
||||
};
|
||||
refresh_file_explorer(true, Some(cursor), cx, root);
|
||||
refresh_file_explorer(cursor, cx, root);
|
||||
|
||||
Some(Ok(format!("Created file: {}", to_create.display())))
|
||||
}
|
||||
|
@ -533,7 +527,7 @@ pub fn file_explorer(
|
|||
}) {
|
||||
return Some(Err(err));
|
||||
};
|
||||
refresh_file_explorer(true, Some(cursor), cx, root);
|
||||
refresh_file_explorer(cursor, cx, root);
|
||||
None
|
||||
};
|
||||
|
||||
|
@ -587,7 +581,7 @@ pub fn file_explorer(
|
|||
}) {
|
||||
return Some(Err(err));
|
||||
};
|
||||
refresh_file_explorer(true, Some(cursor), cx, root);
|
||||
refresh_file_explorer(cursor, cx, root);
|
||||
|
||||
Some(Ok(format!("Deleted directory: {}", to_delete.display())))
|
||||
} else {
|
||||
|
@ -596,7 +590,7 @@ pub fn file_explorer(
|
|||
}) {
|
||||
return Some(Err(err));
|
||||
};
|
||||
refresh_file_explorer(true, Some(cursor), cx, root);
|
||||
refresh_file_explorer(cursor, cx, root);
|
||||
|
||||
Some(Ok(format!("Deleted file: {}", to_delete.display())))
|
||||
}
|
||||
|
@ -636,7 +630,7 @@ pub fn file_explorer(
|
|||
}) {
|
||||
return Some(Err(err));
|
||||
};
|
||||
refresh_file_explorer(true, Some(cursor), cx, root);
|
||||
refresh_file_explorer(cursor, cx, root);
|
||||
|
||||
Some(Ok(format!(
|
||||
"Copied contents of file {} to {}",
|
||||
|
@ -687,7 +681,16 @@ pub fn file_explorer(
|
|||
move |cx, (path, is_dir): &(PathBuf, bool), action| {
|
||||
if *is_dir {
|
||||
let new_root = helix_stdx::path::normalize(path);
|
||||
refresh_file_explorer(false, None, cx, new_root);
|
||||
let callback = Box::pin(async move {
|
||||
let call: Callback =
|
||||
Callback::EditorCompositor(Box::new(move |editor, compositor| {
|
||||
if let Ok(picker) = file_explorer(None, new_root, editor) {
|
||||
compositor.push(Box::new(overlay::overlaid(picker)));
|
||||
}
|
||||
}));
|
||||
Ok(call)
|
||||
});
|
||||
cx.jobs.callback(callback);
|
||||
} else if let Err(e) = cx.editor.open(path, action) {
|
||||
let err = if let Some(err) = e.source() {
|
||||
format!("{}", err)
|
||||
|
|
Loading…
Add table
Reference in a new issue