handle all available events per frame

This commit is contained in:
alice pellerin
2026-03-24 17:48:12 -05:00
parent a6cf1831c0
commit 7c32ecfa64
2 changed files with 11 additions and 2 deletions
+10 -2
View File
@@ -1,4 +1,4 @@
use std::{env, process::exit}; use std::{env, process::exit, time::Duration};
use crossterm::{ExecutableCommand, event::{self, DisableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind}, terminal::window_size}; use crossterm::{ExecutableCommand, event::{self, DisableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind}, terminal::window_size};
use ratatui::{DefaultTerminal, style::Stylize, text::Span}; use ratatui::{DefaultTerminal, style::Stylize, text::Span};
use crate::{BYTES_PER_LINE, action::AppAction, buffer::Buffer, config::Config, cursor::Cursor}; use crate::{BYTES_PER_LINE, action::AppAction, buffer::Buffer, config::Config, cursor::Cursor};
@@ -67,10 +67,18 @@ impl App {
} }
pub fn handle_events(&mut self, terminal: &mut DefaultTerminal) { pub fn handle_events(&mut self, terminal: &mut DefaultTerminal) {
self.handle_event(terminal);
while event::poll(Duration::ZERO).unwrap() {
self.handle_event(terminal);
}
}
pub fn handle_event(&mut self, terminal: &mut DefaultTerminal) {
match event::read().unwrap() { match event::read().unwrap() {
Event::Resize(_, height) => { Event::Resize(_, height) => {
self.window_size.rows = height as usize; self.window_size.rows = height as usize;
self.buffers[self.current_buffer_index] self.buffers[self.current_buffer_index]
.clamp_screen_to_primary_cursor(self.window_size); .clamp_screen_to_primary_cursor(self.window_size);
} }
+1
View File
@@ -30,6 +30,7 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE;
// - search // - search
// - ascii and bytes (`/` and `A-/`?) // - ascii and bytes (`/` and `A-/`?)
// - diffing // - diffing
// - doesn't have to be anything fancy, just compare each byte 1:1
// - s/A-k/A-K // - s/A-k/A-K
// - sm select marks // - sm select marks
// - C-a/C-x // - C-a/C-x