mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 14:51:03 +00:00
feat: new key-close DDS event (#3925)
This commit is contained in:
parent
1caa5807c6
commit
740d891989
5 changed files with 21 additions and 10 deletions
|
|
@ -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<SparkKind> {
|
||||
Some(SparkKind::KeyClose).filter(|_| cx.source().is_key())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ActionCow> for QuitForm {
|
|||
}
|
||||
|
||||
impl FromLua for QuitForm {
|
||||
fn from_lua(value: Value, lua: &Lua) -> mlua::Result<Self> {
|
||||
Ok(Self { opt: <_>::from_lua(value, lua)? })
|
||||
}
|
||||
fn from_lua(value: Value, lua: &Lua) -> mlua::Result<Self> { lua.from_value(value) }
|
||||
}
|
||||
|
||||
impl IntoLua for QuitForm {
|
||||
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { self.opt.into_lua(lua) }
|
||||
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { lua.to_value_with(&self, SER_OPT) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ActionCow> for CloseForm {
|
|||
}
|
||||
|
||||
impl FromLua for CloseForm {
|
||||
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
|
||||
fn from_lua(value: Value, lua: &Lua) -> mlua::Result<Self> { lua.from_value(value) }
|
||||
}
|
||||
|
||||
impl IntoLua for CloseForm {
|
||||
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
|
||||
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { lua.to_value_with(&self, SER_OPT) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ pub enum SparkKind {
|
|||
// app:title
|
||||
IndAppTitle,
|
||||
|
||||
// mgr:close
|
||||
KeyClose,
|
||||
// mgr:hidden
|
||||
KeyHidden,
|
||||
IndHidden,
|
||||
|
|
|
|||
|
|
@ -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)?),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue