1
0
Fork 0
mirror of https://github.com/helix-editor/helix synced 2024-06-07 09:46:06 +02:00
This commit is contained in:
Blaž Hrastnik 2020-12-07 15:18:37 +09:00
parent 83f2c24115
commit be3c021046
2 changed files with 17 additions and 7 deletions

View File

@ -8,7 +8,7 @@
Document, Editor, Theme, View,
};
use crate::compositor::{Component, Compositor};
use crate::compositor::{Component, Compositor, EventResult};
use log::{debug, info};
@ -383,7 +383,7 @@ fn new(editor: Editor) -> Self {
}
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 @@ fn handle_event(&mut self, event: Event, executor: &smol::Executor) -> bool {
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 @@ fn handle_event(&mut self, event: Event, executor: &smol::Executor) -> bool {
.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 @@ fn handle_event(&mut self, event: Event, executor: &smol::Executor) -> bool {
}
}
}
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 @@ pub fn new(mut args: Args, executor: &'a smol::Executor<'a>) -> Result<Self, Err
}
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();

View File

@ -18,9 +18,17 @@
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.