From b21224cf1ca620d4c0cc113f7020e57e402c1c0f Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Wed, 5 Sep 2018 08:51:32 -0700 Subject: [PATCH] Add EventResult::and --- src/event.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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