summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-10 23:01:49 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-10 23:01:49 -0500
commit5c6400c5635362ccbb39e0324a4681d4029d3f74 (patch)
tree4a4166bdbffe11a315fce0b8e39f148b92180070 /src/state.rs
parent58979a8db547a1083778951d6376a27930006cbc (diff)
downloadnbsh-5c6400c5635362ccbb39e0324a4681d4029d3f74.tar.gz
nbsh-5c6400c5635362ccbb39e0324a4681d4029d3f74.zip
fix some scrolling edge cases
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/state.rs b/src/state.rs
index 5cc18f3..12317f4 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -36,7 +36,9 @@ impl State {
} else {
match self.focus {
crate::action::Focus::Readline => {
- self.readline.handle_key(key).await
+ self.readline
+ .handle_key(key, self.history.entry_count())
+ .await
}
crate::action::Focus::History(idx) => {
self.history.handle_key(key, idx).await;
@@ -226,17 +228,7 @@ impl State {
self.focus = crate::action::Focus::History(idx);
self.hide_readline = true;
}
- crate::action::Action::UpdateFocus(mut new_focus) => {
- match new_focus {
- crate::action::Focus::Readline
- | crate::action::Focus::Scrolling(None) => {}
- crate::action::Focus::History(ref mut idx)
- | crate::action::Focus::Scrolling(Some(ref mut idx)) => {
- if *idx >= self.history.entry_count() {
- *idx = self.history.entry_count() - 1;
- }
- }
- }
+ crate::action::Action::UpdateFocus(new_focus) => {
self.focus = new_focus;
self.hide_readline = false;
self.scene = self.default_scene(new_focus).await;
@@ -290,7 +282,14 @@ impl State {
fn scroll_up(&self, idx: Option<usize>) -> Option<usize> {
idx.map_or_else(
- || Some(self.history.entry_count() - 1),
+ || {
+ let count = self.history.entry_count();
+ if count == 0 {
+ None
+ } else {
+ Some(count - 1)
+ }
+ },
|idx| Some(idx.saturating_sub(1)),
)
}