on master help sign in
Simplify the compositor callback.
commit1255bcb8a311c7f382f0bf66bbe791c6dfd77b30 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 9 May 2021, 18:02 (5 years ago) parent35606a3
6 files changed+22−30
helix-term/src/commands.rs+3−3 helix-term/src/compositor.rs+3−3 helix-term/src/ui/menu.rs+4−6 helix-term/src/ui/picker.rs+4−6 helix-term/src/ui/popup.rs+4−6 helix-term/src/ui/prompt.rs+4−6
helix-term/src/commands.rs+3−3
@@ -63,9 +63,9 @@ impl<'a> Context<'a> {
6363
6464 /// Push a new component onto the compositor.
6565 pub fn push_layer(&mut self, mut component: Box<dyn Component>) {
66− self.callback = Some(Box::new(
67− |compositor: &mut Compositor, editor: &mut Editor| compositor.push(component),
68− ));
66+ self.callback = Some(Box::new(|compositor: &mut Compositor| {
67+ compositor.push(component)
68+ }));
6969 }
7070
7171 #[inline]
helix-term/src/compositor.rs+3−3
@@ -6,7 +6,7 @@ use crossterm::event::Event;
66use helix_core::Position;
77use tui::{buffer::Buffer as Surface, layout::Rect};
88
9−pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Editor)>;
9+pub type Callback = Box<dyn FnOnce(&mut Compositor)>;
1010
1111// --> EventResult should have a callback that takes a context with methods like .popup(),
1212// .prompt() etc. That way we can abstract it from the renderer.
@@ -22,7 +22,7 @@ pub enum EventResult {
2222 Consumed(Option<Callback>),
2323}
2424
25−use helix_view::{Editor, View};
25+use helix_view::Editor;
2626
2727use crate::application::LspCallbacks;
2828
@@ -111,7 +111,7 @@ impl Compositor {
111111 for layer in self.layers.iter_mut().rev() {
112112 match layer.handle_event(event, cx) {
113113 EventResult::Consumed(Some(callback)) => {
114− callback(self, cx.editor);
114+ callback(self);
115115 return true;
116116 }
117117 EventResult::Consumed(None) => return true,
helix-term/src/ui/menu.rs+4−6
@@ -142,12 +142,10 @@ impl<T: 'static> Component for Menu<T> {
142142 _ => return EventResult::Ignored,
143143 };
144144
145− let close_fn = EventResult::Consumed(Some(Box::new(
146− |compositor: &mut Compositor, editor: &mut Editor| {
147− // remove the layer
148− compositor.pop();
149− },
150− )));
145+ let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
146+ // remove the layer
147+ compositor.pop();
148+ })));
151149
152150 match event {
153151 // esc or ctrl-c aborts the completion and closes the menu
helix-term/src/ui/picker.rs+4−6
@@ -126,12 +126,10 @@ impl<T: 'static> Component for Picker<T> {
126126 _ => return EventResult::Ignored,
127127 };
128128
129− let close_fn = EventResult::Consumed(Some(Box::new(
130− |compositor: &mut Compositor, editor: &mut Editor| {
131− // remove the layer
132− compositor.pop();
133− },
134− )));
129+ let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
130+ // remove the layer
131+ compositor.pop();
132+ })));
135133
136134 match key_event {
137135 KeyEvent {
helix-term/src/ui/popup.rs+4−6
@@ -66,12 +66,10 @@ impl<T: Component> Component for Popup<T> {
6666 _ => return EventResult::Ignored,
6767 };
6868
69− let close_fn = EventResult::Consumed(Some(Box::new(
70− |compositor: &mut Compositor, editor: &mut Editor| {
71− // remove the layer
72− compositor.pop();
73− },
74− )));
69+ let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
70+ // remove the layer
71+ compositor.pop();
72+ })));
7573
7674 match key {
7775 // esc or ctrl-c aborts the completion and closes the menu
helix-term/src/ui/prompt.rs+4−6
@@ -211,12 +211,10 @@ impl Component for Prompt {
211211 _ => return EventResult::Ignored,
212212 };
213213
214− let close_fn = EventResult::Consumed(Some(Box::new(
215− |compositor: &mut Compositor, editor: &mut Editor| {
216− // remove the layer
217− compositor.pop();
218− },
219− )));
214+ let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
215+ // remove the layer
216+ compositor.pop();
217+ })));
220218
221219 match event {
222220 // char or shift char