JAL-2429 Fix to ColumnSelection::findColumnPosition
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
index 98a7fe2..7459033 100644 (file)
@@ -690,8 +690,8 @@ public class ColumnSelection
    * left-most visible column will always be returned.
    * 
    * @param hiddenColumn
-   *          int
-   * @return int
+   *          the column index in the full alignment including hidden columns
+   * @return the position of the column in the visible alignment
    */
   public int findColumnPosition(int hiddenColumn)
   {
@@ -708,9 +708,17 @@ public class ColumnSelection
           result -= region[1] + 1 - region[0];
         }
       } while ((hiddenColumn > region[1]) && (index < hiddenColumns.size()));
-      if (hiddenColumn > region[0] && hiddenColumn < region[1])
-      {
-        return region[0] + hiddenColumn - result;
+
+      if (hiddenColumn >= region[0] && hiddenColumn <= region[1])
+       {
+         // Here the hidden column is within a region, so
+         // we want to return the position of region[0]-1, adjusted for any
+         // earlier hidden columns.
+         // Calculate the difference between the actual hidden col position
+         // 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);
       }
     }
     return result; // return the shifted position after removing hidden columns.