diff --git a/src/event.rs b/src/event.rs index 674ea04..64759c6 100644 --- a/src/event.rs +++ b/src/event.rs @@ -140,6 +140,25 @@ impl EventResult { other => other, } } + + /// Returns an event result that combines `self` and `other`. + pub fn and(self, other: Self) -> Self { + match (self, other) { + (EventResult::Ignored, result) + | (result, EventResult::Ignored) => result, + (EventResult::Consumed(None), EventResult::Consumed(cb)) + | (EventResult::Consumed(cb), EventResult::Consumed(None)) => { + EventResult::Consumed(cb) + } + ( + EventResult::Consumed(Some(cb1)), + EventResult::Consumed(Some(cb2)), + ) => EventResult::with_cb(move |siv| { + (cb1)(siv); + (cb2)(siv); + }), + } + } } /// A non-character key on the keyboard