mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Feat: Add the url parameter to the create action
This commit is contained in:
parent
bf1274315d
commit
64418f83ec
2 changed files with 28 additions and 8 deletions
|
|
@ -20,15 +20,33 @@ impl Actor for Create {
|
||||||
|
|
||||||
fn act(cx: &mut Ctx, form: Self::Form) -> Result<Data> {
|
fn act(cx: &mut Ctx, form: Self::Form) -> Result<Data> {
|
||||||
let cwd = cx.cwd().to_owned();
|
let cwd = cx.cwd().to_owned();
|
||||||
let mut input = input!(cx, YAZI.input.create(form.dir))?;
|
|
||||||
|
let target = if let Some(target) = form.target {
|
||||||
|
let target_str = target.loc().to_str()?.to_string();
|
||||||
|
if target_str.is_empty() { None } else { Some(target_str) }
|
||||||
|
} else { None };
|
||||||
|
|
||||||
|
let input = if target.is_some() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(input!(cx, YAZI.input.create(form.dir))?)
|
||||||
|
};
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let Some(InputEvent::Submit(name)) = input.recv().await else { return };
|
|
||||||
if name.is_empty() {
|
let target = match input {
|
||||||
|
Some(mut input) => {
|
||||||
|
let Some(InputEvent::Submit(name)) = input.recv().await else { return };
|
||||||
|
name
|
||||||
|
},
|
||||||
|
None => target.unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if target.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Ok(new) = cwd.try_join(&name) else {
|
let Ok(new) = cwd.try_join(&target) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -39,7 +57,7 @@ impl Actor for Create {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = Self::r#do(new, form.dir || name.ends_with('/') || name.ends_with('\\')).await;
|
_ = Self::r#do(new, form.dir || target.ends_with('/') || target.ends_with('\\')).await;
|
||||||
});
|
});
|
||||||
succ!();
|
succ!();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use yazi_shared::event::ActionCow;
|
use yazi_shared::{event::ActionCow, url::UrlBuf};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct CreateForm {
|
pub struct CreateForm {
|
||||||
|
#[serde(alias = "0")]
|
||||||
|
pub target: Option<UrlBuf>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub dir: bool,
|
pub dir: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub force: bool,
|
pub force: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<ActionCow> for CreateForm {
|
impl TryFrom<ActionCow> for CreateForm {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue