JAL-2429 Additional fix to ColumnSelection when hidden cols start at 0
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
index 7459033..a31c686 100644 (file)
@@ -718,7 +718,20 @@ public class ColumnSelection
          // and region[0]-1, and then subtract from result to convert result from
          // the adjusted hiddenColumn value to the adjusted region[0]-1 value
 
-         return result - (hiddenColumn - region[0] + 1);
+        // However, if the region begins at 0 we cannot return region[0]-1
+        // so return region[1] + 1 instead, adjusted for earlier hidden columns,
+        // by calculating the difference between region[1]+1 and the actual
+        // hidden
+        // column, and then adding to result to convert result from the adjusted
+        // hiddenColumn value to the adjusted region[1]+1 value
+        if (region[0] == 0)
+        {
+          return result + (region[1] + 1 - hiddenColumn);
+        }
+        else
+        {
+          return result - (hiddenColumn - region[0] + 1);
+        }
       }
     }
     return result; // return the shifted position after removing hidden columns.