JAL-2573 Fixes for alignment < viewport width, and similarly height
[jalview.git] / src / jalview / viewmodel / ViewportRanges.java
index 56c1d39..743d212 100644 (file)
@@ -139,6 +139,10 @@ public class ViewportRanges extends ViewportProperties
     {
       endRes = 0;
     }
+    else if (end > getVisibleAlignmentWidth() - 1)
+    {
+      endRes = getVisibleAlignmentWidth() - 1;
+    }
     else
     {
       endRes = end;
@@ -326,9 +330,12 @@ public class ViewportRanges extends ViewportProperties
     {
       vpstart = 0;
     }
-    else if (vpstart + w - 1 > getVisibleAlignmentWidth() - 1)
+    else if ((w <= getVisibleAlignmentWidth())
+            && (vpstart + w - 1 > getVisibleAlignmentWidth() - 1))
+    // viewport width is less than the full alignment and we are running off the
+    // RHS edge
     {
-      vpstart = getVisibleAlignmentWidth() - 1;
+      vpstart = getVisibleAlignmentWidth() - w;
     }
     setStartEndRes(vpstart, vpstart + w - 1);
   }
@@ -350,7 +357,10 @@ public class ViewportRanges extends ViewportProperties
     {
       vpstart = 0;
     }
-    else if (vpstart + h - 1 > getVisibleAlignmentHeight() - 1)
+    else if ((h <= getVisibleAlignmentHeight())
+            && (vpstart + h - 1 > getVisibleAlignmentHeight() - 1))
+    // viewport height is less than the full alignment and we are running off
+    // the bottom
     {
       vpstart = getVisibleAlignmentHeight() - h;
     }
@@ -429,7 +439,7 @@ public class ViewportRanges extends ViewportProperties
     }
     else
     {
-      if (endRes > getVisibleAlignmentWidth() - 1)
+      if (endRes >= getVisibleAlignmentWidth() - 1)
       {
         return false;
       }