diff options
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/application.rs | 14 | ||||
-rw-r--r-- | helix-term/src/compositor.rs | 10 |
2 files changed, 17 insertions, 7 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 30258c1d..506735e8 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -8,7 +8,7 @@ use helix_view::{ Document, Editor, Theme, View, }; -use crate::compositor::{Component, Compositor}; +use crate::compositor::{Component, Compositor, EventResult}; use log::{debug, info}; @@ -383,7 +383,7 @@ impl EditorView { } impl Component for EditorView { - fn handle_event(&mut self, event: Event, executor: &smol::Executor) -> bool { + fn handle_event(&mut self, event: Event, executor: &smol::Executor) -> EventResult { match event { Event::Resize(width, height) => { // TODO: simplistic ensure cursor in view for now @@ -392,6 +392,7 @@ impl Component for EditorView { view.size = (width, height); view.ensure_cursor_in_view() }; + EventResult::Consumed(None) } Event::Key(event) => { // if there's a prompt, it takes priority @@ -400,6 +401,7 @@ impl Component for EditorView { .as_mut() .unwrap() .handle_input(event, &mut self.editor); + EventResult::Consumed(None) } else if let Some(view) = self.editor.view_mut() { let keys = vec![event]; // TODO: sequences (`gg`) @@ -511,12 +513,13 @@ impl Component for EditorView { } } } + EventResult::Consumed(None) + } else { + EventResult::Ignored } } - Event::Mouse(_) => (), + Event::Mouse(_) => EventResult::Ignored, } - - true } fn render(&mut self, renderer: &mut Renderer) { const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter @@ -569,7 +572,6 @@ impl<'a> Application<'a> { } fn render(&mut self) { - // v2: self.renderer.surface.reset(); // reset is faster than allocating new empty surface self.compositor.render(&mut self.renderer); // viewport, self.renderer.draw_and_swap(); diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 187c5692..f859f947 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -18,9 +18,17 @@ use crossterm::event::Event; use smol::Executor; use tui::buffer::Buffer as Surface; +pub(crate) type Callback = Box<dyn Fn(&mut Compositor)>; + +// Cursive-inspired +pub(crate) enum EventResult { + Ignored, + Consumed(Option<Callback>), +} + pub(crate) trait Component { /// Process input events, return true if handled. - fn handle_event(&mut self, event: Event, executor: &Executor) -> bool; + fn handle_event(&mut self, event: Event, executor: &Executor) -> EventResult; // , args: () /// Should redraw? Useful for saving redraw cycles if we know component didn't change. |