diff options
author | Blaž Hrastnik | 2021-05-09 09:02:31 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-05-09 09:02:31 +0000 |
commit | 1255bcb8a311c7f382f0bf66bbe791c6dfd77b30 (patch) | |
tree | 365cb67c8cf4942a841a6e42176642f0882b04df /helix-term | |
parent | 35606a3daa7ee273845a12f3e03728e0ae23928e (diff) |
Simplify the compositor callback.
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 6 | ||||
-rw-r--r-- | helix-term/src/compositor.rs | 6 | ||||
-rw-r--r-- | helix-term/src/ui/menu.rs | 10 | ||||
-rw-r--r-- | helix-term/src/ui/picker.rs | 10 | ||||
-rw-r--r-- | helix-term/src/ui/popup.rs | 10 | ||||
-rw-r--r-- | helix-term/src/ui/prompt.rs | 10 |
6 files changed, 22 insertions, 30 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index fe160ab8..e26dbbaa 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -63,9 +63,9 @@ impl<'a> Context<'a> { /// Push a new component onto the compositor. pub fn push_layer(&mut self, mut component: Box<dyn Component>) { - self.callback = Some(Box::new( - |compositor: &mut Compositor, editor: &mut Editor| compositor.push(component), - )); + self.callback = Some(Box::new(|compositor: &mut Compositor| { + compositor.push(component) + })); } #[inline] diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 7b828358..3a17904d 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -6,7 +6,7 @@ use crossterm::event::Event; use helix_core::Position; use tui::{buffer::Buffer as Surface, layout::Rect}; -pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Editor)>; +pub type Callback = Box<dyn FnOnce(&mut Compositor)>; // --> EventResult should have a callback that takes a context with methods like .popup(), // .prompt() etc. That way we can abstract it from the renderer. @@ -22,7 +22,7 @@ pub enum EventResult { Consumed(Option<Callback>), } -use helix_view::{Editor, View}; +use helix_view::Editor; use crate::application::LspCallbacks; @@ -111,7 +111,7 @@ impl Compositor { for layer in self.layers.iter_mut().rev() { match layer.handle_event(event, cx) { EventResult::Consumed(Some(callback)) => { - callback(self, cx.editor); + callback(self); return true; } EventResult::Consumed(None) => return true, diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index d055d0d0..f9bfdd35 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -142,12 +142,10 @@ impl<T: 'static> Component for Menu<T> { _ => return EventResult::Ignored, }; - let close_fn = EventResult::Consumed(Some(Box::new( - |compositor: &mut Compositor, editor: &mut Editor| { - // remove the layer - compositor.pop(); - }, - ))); + let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { + // remove the layer + compositor.pop(); + }))); match event { // esc or ctrl-c aborts the completion and closes the menu diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 73cbf07f..6d77bf1d 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -126,12 +126,10 @@ impl<T: 'static> Component for Picker<T> { _ => return EventResult::Ignored, }; - let close_fn = EventResult::Consumed(Some(Box::new( - |compositor: &mut Compositor, editor: &mut Editor| { - // remove the layer - compositor.pop(); - }, - ))); + let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { + // remove the layer + compositor.pop(); + }))); match key_event { KeyEvent { diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 44e79c4f..7ce7166c 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -66,12 +66,10 @@ impl<T: Component> Component for Popup<T> { _ => return EventResult::Ignored, }; - let close_fn = EventResult::Consumed(Some(Box::new( - |compositor: &mut Compositor, editor: &mut Editor| { - // remove the layer - compositor.pop(); - }, - ))); + let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { + // remove the layer + compositor.pop(); + }))); match key { // esc or ctrl-c aborts the completion and closes the menu diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 0c2c1d8a..b09b8e14 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -211,12 +211,10 @@ impl Component for Prompt { _ => return EventResult::Ignored, }; - let close_fn = EventResult::Consumed(Some(Box::new( - |compositor: &mut Compositor, editor: &mut Editor| { - // remove the layer - compositor.pop(); - }, - ))); + let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { + // remove the layer + compositor.pop(); + }))); match event { // char or shift char |