Refactored to require handlers to specify the components they rely on and to specify when they are ready. This fixes a lot of bugs with the UI when users try to press buttons while the application is still loading.

This commit is contained in:
2024-07-17 19:55:10 -06:00
parent 9104b7c356
commit d84e7dfcab
49 changed files with 5143 additions and 265 deletions
+36 -7
View File
@@ -19,17 +19,45 @@ pub trait KeyEventHandler<'a, 'b, T: Into<Route>> {
fn handle_key_event(&mut self) {
let key = self.get_key();
match key {
_ if *key == DEFAULT_KEYBINDINGS.up.key => self.handle_scroll_up(),
_ if *key == DEFAULT_KEYBINDINGS.down.key => self.handle_scroll_down(),
_ if *key == DEFAULT_KEYBINDINGS.home.key => self.handle_home(),
_ if *key == DEFAULT_KEYBINDINGS.end.key => self.handle_end(),
_ if *key == DEFAULT_KEYBINDINGS.delete.key => self.handle_delete(),
_ if *key == DEFAULT_KEYBINDINGS.up.key => {
if self.is_ready() {
self.handle_scroll_up();
}
}
_ if *key == DEFAULT_KEYBINDINGS.down.key => {
if self.is_ready() {
self.handle_scroll_down();
}
}
_ if *key == DEFAULT_KEYBINDINGS.home.key => {
if self.is_ready() {
self.handle_home();
}
}
_ if *key == DEFAULT_KEYBINDINGS.end.key => {
if self.is_ready() {
self.handle_end();
}
}
_ if *key == DEFAULT_KEYBINDINGS.delete.key => {
if self.is_ready() {
self.handle_delete();
}
}
_ if *key == DEFAULT_KEYBINDINGS.left.key || *key == DEFAULT_KEYBINDINGS.right.key => {
self.handle_left_right_action()
}
_ if *key == DEFAULT_KEYBINDINGS.submit.key => self.handle_submit(),
_ if *key == DEFAULT_KEYBINDINGS.submit.key => {
if self.is_ready() {
self.handle_submit();
}
}
_ if *key == DEFAULT_KEYBINDINGS.esc.key => self.handle_esc(),
_ => self.handle_char_key_event(),
_ => {
if self.is_ready() {
self.handle_char_key_event();
}
}
}
}
@@ -40,6 +68,7 @@ pub trait KeyEventHandler<'a, 'b, T: Into<Route>> {
fn accepts(active_block: &'a T) -> bool;
fn with(key: &'a Key, app: &'a mut App<'b>, active_block: &'a T, context: &'a Option<T>) -> Self;
fn get_key(&self) -> &Key;
fn is_ready(&self) -> bool;
fn handle_scroll_up(&mut self);
fn handle_scroll_down(&mut self);
fn handle_home(&mut self);