From: kiramt Date: Tue, 7 Mar 2017 09:35:14 +0000 (+0000) Subject: JAL-2429 findColumnPosition returns 0 for cols in region starting at 0 X-Git-Tag: Release_2_10_2~3^2~92^2~51 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=956ae1ec0680e5567994197641be358d6bd15a83;p=jalview.git JAL-2429 findColumnPosition returns 0 for cols in region starting at 0 --- diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 7459033..28745f1 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -718,7 +718,16 @@ 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 + // just return 0 + if (region[0] == 0) + { + return 0; + } + 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..5a915ce 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 + // is returned as 0 + ColumnSelection cs3 = new ColumnSelection(); + cs3.hideColumns(0, 4); + assertEquals(0, cs3.findColumnPosition(2)); + } /**