[tor-commits] [nyx/master] Scrollbars never reached bottom

atagar at torproject.org atagar at torproject.org
Wed Aug 9 19:20:54 UTC 2017


commit 0aa4dcb621c1fa2e2f873636228958bc1d278c39
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Aug 9 12:19:35 2017 -0700

    Scrollbars never reached bottom
    
    Damn the scrollbars have been a bigger headache than anything else thus far.
    There was an off-by-one error where we compared the number of scroll elements
    to the last index.
---
 nyx/curses.py     | 5 +++--
 test/subwindow.py | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/nyx/curses.py b/nyx/curses.py
index d1cd5eb..2cb1b42 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -872,10 +872,11 @@ class _Subwindow(object):
     slider_size = (scrollbar_height * (bottom_index - top_index + 1)) // size
     max_slider_top = scrollbar_height - slider_size - 1
 
-    # ensures slider isn't at top or bottom unless really at those extreme bounds
+    # Ensures slider isn't at top or bottom unless really at those extreme
+    # bounds. This is an index vs size comparison, hence the -1 offset.
 
     slider_top = 0 if top_index == 0 else max(slider_top, 1)
-    slider_top = max_slider_top if bottom_index == size else min(slider_top, max_slider_top - 1)
+    slider_top = max_slider_top if bottom_index == size - 1 else min(slider_top, max_slider_top - 1)
 
     # draws scrollbar slider
 
diff --git a/test/subwindow.py b/test/subwindow.py
index bee91f3..bc7ce5a 100644
--- a/test/subwindow.py
+++ b/test/subwindow.py
@@ -143,7 +143,7 @@ class TestCurses(unittest.TestCase):
   @require_curses
   def test_scrollbar_bottom(self):
     def _draw(subwindow):
-      subwindow.scrollbar(15, 21, 30, fill_char = '*')
+      subwindow.scrollbar(15, 20, 30, fill_char = '*')
 
     self.assertEqual(EXPECTED_SCROLLBAR_BOTTOM, test.render(_draw).content.strip())
 



More information about the tor-commits mailing list