1- use std:: { ops:: Deref , sync :: Arc } ;
1+ use std:: ops:: Deref ;
22
3- use mlua:: { ExternalError , FromLua , IntoLua , Lua , LuaSerdeExt , Table , UserData , UserDataFields , Value } ;
3+ use mlua:: { ExternalError , FromLua , IntoLua , Lua , Table , UserData , UserDataFields , Value } ;
4+ use serde:: Deserialize ;
5+ use yazi_codegen:: FromLuaOwned ;
46use yazi_shim:: mlua:: UserDataFieldsExt ;
57
6- use crate :: { Id , Iter , event:: Action , keymap:: Key } ;
8+ use crate :: { Id , Iter , event:: Actions , keymap:: Key } ;
79
10+ #[ derive( FromLuaOwned ) ]
811pub struct Chord {
9- inner : Arc < yazi_config:: keymap:: Chord > ,
12+ inner : yazi_config:: keymap:: ChordArc ,
1013}
1114
1215impl Deref for Chord {
13- type Target = Arc < yazi_config:: keymap:: Chord > ;
16+ type Target = yazi_config:: keymap:: ChordArc ;
1417
1518 fn deref ( & self ) -> & Self :: Target { & self . inner }
1619}
1720
18- impl From < Chord > for Arc < yazi_config:: keymap:: Chord > {
21+ impl From < & yazi_config:: keymap:: ChordArc > for Chord {
22+ fn from ( value : & yazi_config:: keymap:: ChordArc ) -> Self { Self { inner : value. clone ( ) } }
23+ }
24+
25+ impl From < Chord > for yazi_config:: keymap:: ChordArc {
1926 fn from ( value : Chord ) -> Self { value. inner }
2027}
2128
2229impl Chord {
23- pub fn new ( inner : impl Into < Arc < yazi_config:: keymap:: Chord > > ) -> Self {
30+ pub fn new ( inner : impl Into < yazi_config:: keymap:: ChordArc > ) -> Self {
2431 Self { inner : inner. into ( ) }
2532 }
2633}
2734
28- impl FromLua for Chord {
29- fn from_lua ( value : Value , lua : & Lua ) -> mlua:: Result < Self > {
30- Ok ( Self :: new ( lua. from_value :: < yazi_config:: keymap:: Chord > ( value) ?) )
35+ impl TryFrom < ( Value , yazi_shared:: Layer ) > for Chord {
36+ type Error = mlua:: Error ;
37+
38+ fn try_from ( ( value, layer) : ( Value , yazi_shared:: Layer ) ) -> Result < Self , Self :: Error > {
39+ use yazi_config:: keymap:: Chord as C ;
40+ use yazi_shared:: Layer as L ;
41+
42+ let de = mlua:: serde:: Deserializer :: new ( value) ;
43+ let inner = match layer {
44+ L :: Null => C :: < { L :: Null as u8 } > :: deserialize ( de) ?. into ( ) ,
45+ L :: App => C :: < { L :: App as u8 } > :: deserialize ( de) ?. into ( ) ,
46+ L :: Mgr => C :: < { L :: Mgr as u8 } > :: deserialize ( de) ?. into ( ) ,
47+ L :: Tasks => C :: < { L :: Tasks as u8 } > :: deserialize ( de) ?. into ( ) ,
48+ L :: Spot => C :: < { L :: Spot as u8 } > :: deserialize ( de) ?. into ( ) ,
49+ L :: Pick => C :: < { L :: Pick as u8 } > :: deserialize ( de) ?. into ( ) ,
50+ L :: Input => C :: < { L :: Input as u8 } > :: deserialize ( de) ?. into ( ) ,
51+ L :: Confirm => C :: < { L :: Confirm as u8 } > :: deserialize ( de) ?. into ( ) ,
52+ L :: Help => C :: < { L :: Help as u8 } > :: deserialize ( de) ?. into ( ) ,
53+ L :: Cmp => C :: < { L :: Cmp as u8 } > :: deserialize ( de) ?. into ( ) ,
54+ L :: Which => C :: < { L :: Which as u8 } > :: deserialize ( de) ?. into ( ) ,
55+ L :: Notify => C :: < { L :: Notify as u8 } > :: deserialize ( de) ?. into ( ) ,
56+ } ;
57+
58+ Ok ( Self { inner } )
3159 }
3260}
3361
@@ -38,9 +66,7 @@ impl UserData for Chord {
3866 fields
3967 . add_cached_field ( "on" , |lua, me| lua. create_sequence_from ( me. on . iter ( ) . copied ( ) . map ( Key ) ) ) ;
4068
41- fields. add_cached_field ( "run" , |lua, me| {
42- lua. create_sequence_from ( me. run . iter ( ) . cloned ( ) . map ( Action :: new) )
43- } ) ;
69+ fields. add_cached_field ( "run" , |_, me| Ok ( Actions :: new ( me. run . clone ( ) ) ) ) ;
4470
4571 fields. add_cached_field ( "desc" , |lua, me| lua. create_string ( & me. desc ) ) ;
4672 }
0 commit comments