diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 6148531e6e01bf7fd68d1816e13e0e91689a7b47..d21a1059efa4ab746ff4e775cd36e5a29988f4d4 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -94,41 +94,16 @@ pub trait UpdateView { pub trait Action: 'static + AnyAction { type Argument: 'static + Clone; - - const NAME: &'static str; } pub trait AnyAction { fn id(&self) -> TypeId; + fn name(&self) -> &'static str; fn as_any(&self) -> &dyn Any; fn boxed_clone(&self) -> Box; fn boxed_clone_as_any(&self) -> Box; } -impl Action for () { - type Argument = (); - - const NAME: &'static str = "()"; -} - -impl AnyAction for () { - fn id(&self) -> TypeId { - TypeId::of::<()>() - } - - fn as_any(&self) -> &dyn Any { - self - } - - fn boxed_clone(&self) -> Box { - Box::new(()) - } - - fn boxed_clone_as_any(&self) -> Box { - Box::new(()) - } -} - #[macro_export] macro_rules! action { ($name:ident, $arg:ty) => { @@ -137,8 +112,6 @@ macro_rules! action { impl $crate::Action for $name { type Argument = $arg; - - const NAME: &'static str = stringify!($name); } impl $crate::AnyAction for $name { @@ -146,6 +119,10 @@ macro_rules! action { std::any::TypeId::of::<$name>() } + fn name(&self) -> &'static str { + stringify!($name) + } + fn as_any(&self) -> &dyn std::any::Any { self } @@ -166,8 +143,6 @@ macro_rules! action { impl $crate::Action for $name { type Argument = (); - - const NAME: &'static str = stringify!($name); } impl $crate::AnyAction for $name { @@ -175,16 +150,20 @@ macro_rules! action { std::any::TypeId::of::<$name>() } + fn name(&self) -> &'static str { + stringify!($name) + } + fn as_any(&self) -> &dyn std::any::Any { self } fn boxed_clone(&self) -> Box { - Box::new(()) + Box::new(self.clone()) } fn boxed_clone_as_any(&self) -> Box { - Box::new(()) + Box::new(self.clone()) } } }; diff --git a/gpui/src/keymap.rs b/gpui/src/keymap.rs index 409366419394ba07be9230b70670b40be9d79157..b1082123bccc772a8f820744a427e491db06bd19 100644 --- a/gpui/src/keymap.rs +++ b/gpui/src/keymap.rs @@ -455,23 +455,23 @@ mod tests { assert_eq!(matcher.test_keystroke("a", 1, &ctx_a), Some(A("x"))); // Multi-keystroke match - assert_eq!(matcher.test_keystroke::<()>("a", 1, &ctx_b), None); + assert_eq!(matcher.test_keystroke::("a", 1, &ctx_b), None); assert_eq!(matcher.test_keystroke("b", 1, &ctx_b), Some(Ab)); // Failed matches don't interfere with matching subsequent keys - assert_eq!(matcher.test_keystroke::<()>("x", 1, &ctx_a), None); + assert_eq!(matcher.test_keystroke::("x", 1, &ctx_a), None); assert_eq!(matcher.test_keystroke("a", 1, &ctx_a), Some(A("x"))); // Pending keystrokes are cleared when the context changes - assert_eq!(matcher.test_keystroke::<()>("a", 1, &ctx_b), None); + assert_eq!(matcher.test_keystroke::("a", 1, &ctx_b), None); assert_eq!(matcher.test_keystroke("b", 1, &ctx_a), Some(B)); let mut ctx_c = Context::default(); ctx_c.set.insert("c".into()); // Pending keystrokes are maintained per-view - assert_eq!(matcher.test_keystroke::<()>("a", 1, &ctx_b), None); - assert_eq!(matcher.test_keystroke::<()>("a", 2, &ctx_c), None); + assert_eq!(matcher.test_keystroke::("a", 1, &ctx_b), None); + assert_eq!(matcher.test_keystroke::("a", 2, &ctx_c), None); assert_eq!(matcher.test_keystroke("b", 1, &ctx_b), Some(Ab)); Ok(())