From d387f0ee40a8e248ce08c97aca2e427aa75a40d8 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 7 Mar 2017 09:35:14 +0000 Subject: [PATCH] JAL-2429 Additional fix to ColumnSelection when hidden cols start at 0 --- src/jalview/datamodel/ColumnSelection.java | 15 ++++++++++++++- test/jalview/datamodel/ColumnSelectionTest.java | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 7459033..a31c686 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -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. diff --git a/test/jalview/datamodel/ColumnSelectionTest.java b/test/jalview/datamodel/ColumnSelectionTest.java index 63d5e56..e34b23f 100644 --- a/test/jalview/datamodel/ColumnSelectionTest.java +++ b/test/jalview/datamodel/ColumnSelectionTest.java @@ -130,6 +130,13 @@ public class ColumnSelectionTest // and moves column 40 to 25 assertEquals(25, cs2.findColumnPosition(40)); + + // check when hidden columns start at 0 that the visible column + // to the right is returned for hidden cols in the region + ColumnSelection cs3 = new ColumnSelection(); + cs3.hideColumns(0, 4); + assertEquals(5, cs3.findColumnPosition(2)); + } /** -- 1.7.10.2