JAL-4375 Fix big sideways scroll from trackpad at beginning and end of visible alignment.
[jalview.git] / src / jalview / viewmodel / ViewportRanges.java
index f842736..03d4172 100644 (file)
@@ -530,21 +530,24 @@ public class ViewportRanges extends ViewportProperties
   {
     if (!right)
     {
-      if (startRes < jump)
+      if (startRes < 1)
       {
         return false;
       }
-
-      setStartRes(startRes - jump);
+      int jumpto = Math.max(startRes - jump, 0);
+      setStartRes(jumpto);
     }
     else
     {
-      if (endRes >= getVisibleAlignmentWidth() - jump)
+      int vawidth = getVisibleAlignmentWidth();
+      if (endRes >= vawidth - 1)
       {
         return false;
       }
 
-      setStartRes(startRes + jump);
+      int jumpto = Math.min(startRes + jump,
+              vawidth - (endRes - startRes + 1));
+      setStartRes(jumpto);
     }
 
     return true;