Author: Stephen Zander <gibreel@debian.org>
Description: make ListBox.pm keep the bottom element of a list in view when
paging down & the top element of a list in view when paging up,
Bug: #171719

--- a/Widgets/ListBox.pm
+++ b/Widgets/ListBox.pm
@@ -314,6 +314,8 @@ sub input_key {
   my $sel = $$conf{VALUE};
   my @items = @{$$conf{LISTITEMS}};
   my $pos = $$conf{CURSORPOS};
+  my $top = $$conf{TOPELEMENT};
+  my $lines = $$conf{LINES};
   my $re = $$conf{TOGGLE};
   my $np;
 
@@ -337,17 +339,23 @@ sub input_key {
       if ($in eq KEY_HOME) {
         beep if $pos == 0;
         $pos = 0;
+        $top = 0;
       } elsif ($in eq KEY_END) {
         beep if $pos == $#items;
         $pos = $#items;
+        $top = $#items - $lines + 1;
       } elsif ($in eq KEY_PPAGE) {
         beep if $pos == 0;
-        $pos -= $$conf{LINES};
+        $pos -= ($lines - 1);
+        $top -= ($lines - 1);
         $pos = 0 if $pos < 0;
+        $top = 0 if $top < 0;
       } elsif ($in eq KEY_NPAGE) {
         beep if $pos == $#items;
-        $pos += $$conf{LINES};
+        $pos += ($lines - 1);
+        $top += ($lines - 1);
         $pos = $#items if $pos > $#items;
+        $top = ($#items - $lines + 1) if $pos > ($#items - $lines + 1);
       }
     } else {
       beep;
@@ -377,7 +385,7 @@ sub input_key {
   }
 
   # Save the changes
-  @$conf{qw(VALUE CURSORPOS)} = ($sel, $pos);
+  @$conf{qw(VALUE CURSORPOS TOPELEMENT)} = ($sel, $pos, $top);
 }
 
 sub match_key {
