# HG changeset patch
# User Dominic LoBue <dominic.lobue@gmail.com>
# Date 1259382719 28800
# Node ID 7a77e42b398f87280969e68654360560d6b50947
# Parent  97578e828e8f47428a8cc305c472457e877ff129
bug fix to scroll snapping in listboxes when the widget that would have been snapped to is larger than the max amount of rows available. Instead widget is snapped to the side scrolled from. Also, added boolean _snap attribute for easy disabling of scroll snapping

diff -r 97578e828e8f -r 7a77e42b398f urwid/listbox.py
--- a/urwid/listbox.py	Wed Nov 04 21:13:28 2009 -0500
+++ b/urwid/listbox.py	Fri Nov 27 20:31:59 2009 -0800
@@ -157,6 +157,7 @@
     pass
 
 class ListBox(BoxWidget):
+    _snap = True
 
     def __init__(self, body):
         """
@@ -609,14 +610,22 @@
         if ( coming_from == 'above' 
                 and target.selectable()
                 and offset_inset > align_bottom
-                and align_bottom >= offset_inset-snap_rows ):
+                and align_bottom >= offset_inset-snap_rows
+                and self._snap ):
+            if snap_rows >= tgt_rows:
             offset_inset = align_bottom
+            else:
+                offset_inset = align_top
             
         if ( coming_from == 'below' 
                 and target.selectable() 
                 and offset_inset < align_top
-                and align_top <= offset_inset+snap_rows ):
+                and align_top <= offset_inset+snap_rows
+                and self._snap ):
+            if snap_rows >= tgt_rows:
             offset_inset = align_top
+            else:
+                offset_inset = align_bottom
         
         # convert offset_inset to offset_rows or inset_fraction
         if offset_inset >= 0:
