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