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/state.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/state.rs') 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