mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 17:36:19 +04:00
Simplify the compositor callback.
This commit is contained in:
parent
35606a3daa
commit
1255bcb8a3
@ -63,9 +63,9 @@ pub fn current(&mut self) -> (&mut View, &mut Document) {
|
||||
|
||||
/// 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]
|
||||
|
@ -6,7 +6,7 @@
|
||||
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 @@ pub fn handle_event(&mut self, event: Event, cx: &mut Context) -> bool {
|
||||
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,
|
||||
|
@ -142,12 +142,10 @@ fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
|
||||
_ => 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
|
||||
|
@ -126,12 +126,10 @@ fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
|
||||
_ => 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 {
|
||||
|
@ -66,12 +66,10 @@ fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
|
||||
_ => 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
|
||||
|
@ -211,12 +211,10 @@ fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
|
||||
_ => 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
|
||||
|
Loading…
Reference in New Issue
Block a user