diff --git a/yazi-actor/src/mgr/close.rs b/yazi-actor/src/mgr/close.rs index 44cbc490..61b23b8c 100644 --- a/yazi-actor/src/mgr/close.rs +++ b/yazi-actor/src/mgr/close.rs @@ -1,6 +1,6 @@ use anyhow::Result; use yazi_macro::act; -use yazi_parser::mgr::CloseForm; +use yazi_parser::{mgr::CloseForm, spark::SparkKind}; use yazi_shared::data::Data; use crate::{Actor, Ctx}; @@ -19,4 +19,8 @@ impl Actor for Close { act!(mgr:quit, cx, opt) } } + + fn hook(cx: &Ctx, _form: &Self::Form) -> Option { + Some(SparkKind::KeyClose).filter(|_| cx.source().is_key()) + } } diff --git a/yazi-parser/src/app/quit.rs b/yazi-parser/src/app/quit.rs index 59756cb1..debd4d7b 100644 --- a/yazi-parser/src/app/quit.rs +++ b/yazi-parser/src/app/quit.rs @@ -1,10 +1,12 @@ -use mlua::{FromLua, IntoLua, Lua, Value}; +use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value}; use serde::{Deserialize, Serialize}; +use yazi_binding::SER_OPT; use yazi_core::app::QuitOpt; use yazi_shared::event::ActionCow; #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct QuitForm { + #[serde(flatten)] pub opt: QuitOpt, } @@ -21,11 +23,9 @@ impl TryFrom for QuitForm { } impl FromLua for QuitForm { - fn from_lua(value: Value, lua: &Lua) -> mlua::Result { - Ok(Self { opt: <_>::from_lua(value, lua)? }) - } + fn from_lua(value: Value, lua: &Lua) -> mlua::Result { lua.from_value(value) } } impl IntoLua for QuitForm { - fn into_lua(self, lua: &Lua) -> mlua::Result { self.opt.into_lua(lua) } + fn into_lua(self, lua: &Lua) -> mlua::Result { lua.to_value_with(&self, SER_OPT) } } diff --git a/yazi-parser/src/mgr/close.rs b/yazi-parser/src/mgr/close.rs index 2dee2cd2..0da0e32f 100644 --- a/yazi-parser/src/mgr/close.rs +++ b/yazi-parser/src/mgr/close.rs @@ -1,9 +1,12 @@ -use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; +use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value}; +use serde::{Deserialize, Serialize}; +use yazi_binding::SER_OPT; use yazi_core::app::QuitOpt; use yazi_shared::event::ActionCow; -#[derive(Debug, Default)] +#[derive(Debug, Default, Serialize, Deserialize)] pub struct CloseForm { + #[serde(flatten)] pub opt: QuitOpt, } @@ -16,9 +19,9 @@ impl TryFrom for CloseForm { } impl FromLua for CloseForm { - fn from_lua(_: Value, _: &Lua) -> mlua::Result { Err("unsupported".into_lua_err()) } + fn from_lua(value: Value, lua: &Lua) -> mlua::Result { lua.from_value(value) } } impl IntoLua for CloseForm { - fn into_lua(self, _: &Lua) -> mlua::Result { Err("unsupported".into_lua_err()) } + fn into_lua(self, lua: &Lua) -> mlua::Result { lua.to_value_with(&self, SER_OPT) } } diff --git a/yazi-parser/src/spark/kind.rs b/yazi-parser/src/spark/kind.rs index eb111a5e..382e00ea 100644 --- a/yazi-parser/src/spark/kind.rs +++ b/yazi-parser/src/spark/kind.rs @@ -6,6 +6,8 @@ pub enum SparkKind { // app:title IndAppTitle, + // mgr:close + KeyClose, // mgr:hidden KeyHidden, IndHidden, diff --git a/yazi-parser/src/spark/spark.rs b/yazi-parser/src/spark/spark.rs index 02ea8829..6b82c4db 100644 --- a/yazi-parser/src/spark/spark.rs +++ b/yazi-parser/src/spark/spark.rs @@ -165,6 +165,8 @@ impl<'a> Spark<'a> { // app:title IndAppTitle => Self::AppTitle(<_>::from_lua(value, lua)?), + // mgr:close + KeyClose => Self::Close(<_>::from_lua(value, lua)?), // mgr:hidden KeyHidden => Self::Hidden(<_>::from_lua(value, lua)?), IndHidden => Self::Hidden(<_>::from_lua(value, lua)?),