From 1729d8988a12a097859697f6a9d8041f3a9763fa Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 10 Dec 2021 02:05:05 -0500 Subject: make up and down work --- src/readline.rs | 5 +++++ src/state.rs | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/readline.rs b/src/readline.rs index 0bb304c..eba2a4e 100644 --- a/src/readline.rs +++ b/src/readline.rs @@ -41,6 +41,11 @@ impl Readline { textmode::Key::Backspace => self.backspace(), textmode::Key::Left => self.cursor_left(), textmode::Key::Right => self.cursor_right(), + textmode::Key::Up => { + return Some(crate::action::Action::UpdateFocus( + crate::state::Focus::Scrolling(Some(usize::MAX)), + )) + } _ => {} } Some(crate::action::Action::Render) diff --git a/src/state.rs b/src/state.rs index 49e8320..7269970 100644 --- a/src/state.rs +++ b/src/state.rs @@ -69,12 +69,12 @@ impl State { None } } - textmode::Key::Char('j') => { + textmode::Key::Char('j') | textmode::Key::Down => { Some(crate::action::Action::UpdateFocus(Focus::Scrolling( self.scroll_down(self.focus_idx()), ))) } - textmode::Key::Char('k') => { + textmode::Key::Char('k') | textmode::Key::Up => { Some(crate::action::Action::UpdateFocus(Focus::Scrolling( self.scroll_up(self.focus_idx()), ))) @@ -108,12 +108,12 @@ impl State { None } } - textmode::Key::Char('j') => { + textmode::Key::Char('j') | textmode::Key::Down => { Some(crate::action::Action::UpdateFocus(Focus::Scrolling( self.scroll_down(self.focus_idx()), ))) } - textmode::Key::Char('k') => { + textmode::Key::Char('k') | textmode::Key::Up => { Some(crate::action::Action::UpdateFocus(Focus::Scrolling( self.scroll_up(self.focus_idx()), ))) @@ -212,7 +212,16 @@ impl State { self.focus = Focus::History(idx); self.hide_readline = true; } - crate::action::Action::UpdateFocus(new_focus) => { + crate::action::Action::UpdateFocus(mut new_focus) => { + match new_focus { + Focus::Readline | Focus::Scrolling(None) => {} + Focus::History(ref mut idx) + | Focus::Scrolling(Some(ref mut idx)) => { + if *idx >= self.history.entry_count() { + *idx = self.history.entry_count() - 1; + } + } + } self.focus = new_focus; self.hide_readline = false; self.scene = self.default_scene(new_focus).await; -- cgit v1.2.3-54-g00ecf