aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/compositor.rs
diff options
context:
space:
mode:
authorBram2022-02-23 03:46:12 +0000
committerGitHub2022-02-23 03:46:12 +0000
commit40eb1268c72b60f1249389c58892e7c45d268cff (patch)
tree84f741c7067547b4af3e6b0a867c10639d00ede8 /helix-term/src/compositor.rs
parente1a92fd3998aca2a313d4cbf0aca3157eca0b53f (diff)
Close some popups automatically (#1285)
* Add Event::Used to use event callback without consuming * Close popup if contents ignored event * collect event results before executing callbacks * don't add new result variant, use Ignored(..) instead * break in match cases * Make auto_close configurable * fix merge * auto close hover popups * fix formatting
Diffstat (limited to 'helix-term/src/compositor.rs')
-rw-r--r--helix-term/src/compositor.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index dd7ebe1d..2f80de00 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -19,7 +19,7 @@ pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>;
// Cursive-inspired
pub enum EventResult {
- Ignored,
+ Ignored(Option<Callback>),
Consumed(Option<Callback>),
}
@@ -36,7 +36,7 @@ pub struct Context<'a> {
pub trait Component: Any + AnyComponent {
/// Process input events, return true if handled.
fn handle_event(&mut self, _event: Event, _ctx: &mut Context) -> EventResult {
- EventResult::Ignored
+ EventResult::Ignored(None)
}
// , args: ()
@@ -146,19 +146,34 @@ impl Compositor {
keys.push(key.into());
}
+ let mut callbacks = Vec::new();
+ let mut consumed = false;
+
// propagate events through the layers until we either find a layer that consumes it or we
// run out of layers (event bubbling)
for layer in self.layers.iter_mut().rev() {
match layer.handle_event(event, cx) {
EventResult::Consumed(Some(callback)) => {
- callback(self, cx);
- return true;
+ callbacks.push(callback);
+ consumed = true;
+ break;
+ }
+ EventResult::Consumed(None) => {
+ consumed = true;
+ break;
+ }
+ EventResult::Ignored(Some(callback)) => {
+ callbacks.push(callback);
}
- EventResult::Consumed(None) => return true,
- EventResult::Ignored => false,
+ EventResult::Ignored(None) => {}
};
}
- false
+
+ for callback in callbacks {
+ callback(self, cx)
+ }
+
+ consumed
}
pub fn render(&mut self, cx: &mut Context) {