From 9ac04f2a734da1160b6f4b7866d9e642fb5a41a5 Mon Sep 17 00:00:00 2001 From: Canop Date: Fri, 10 Jan 2020 22:20:22 +0100 Subject: fix scroll adjustement when using the arrow keys (when there's a scrollbar) Fix #112 --- CHANGELOG.md | 8 +++++--- src/flat_tree.rs | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a45f05..e6f9918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ ### master -- backspace was previously bind to back if not consumed by input. This is removed -- fix unsignificative events interpreted as previous event repetition -- fix wrong background applied below sizes +- backspace was previously bound to :back if not consumed by input. This is removed +- fix unsignificative event interpreted as previous event repetition +- fix wrong background applied on sizes in tree display - allow env vars used in verb execution to contain parameters (fix #114) +- allow the use of arrow keys as triggers for verbs (fix #121) +- fix scroll adjustement when using the arrow keys (when there's a scrollbar) (fix #112) ### v0.11.5 - 2020-01-10 diff --git a/src/flat_tree.rs b/src/flat_tree.rs index 8822226..08fdceb 100644 --- a/src/flat_tree.rs +++ b/src/flat_tree.rs @@ -287,10 +287,20 @@ impl Tree { // we adjust the scroll let l = l as i32; let sel = self.selection as i32; - if dy < 0 && sel < self.scroll + 5 { - self.scroll = (self.scroll + 2 * dy).max(0); - } else if dy > 0 && l > page_height && sel > self.scroll + page_height - 5 { - self.scroll += 2 * dy; + if l > page_height { + if dy < 0 { // -1 + if sel == l - 1 { // cycling + self.scroll = l - page_height; + } else if sel < self.scroll + 5 { + self.scroll = (self.scroll + 2 * dy).max(0); + } + } else { // +1 + if sel == 0 { // cycling brought us back to top + self.scroll = 0; + } else if sel > self.scroll + page_height - 5 { + self.scroll = (self.scroll + 2 * dy).min(l - page_height); + } + } } } pub fn try_scroll(&mut self, dy: i32, page_height: i32) { -- cgit v1.2.3