X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=797262656076da8aac1b57cd10b9a149a4da03c0;hb=536caaf2e1766309334134bb4efae5a2365de5fe;hp=9464c7430ea9b6f002391bb92eda14c3efd3a363;hpb=37f0332f53a8564ba7a9d55b993f8bfd2f368c80;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 9464c74..7972626 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -825,7 +825,7 @@ public class Sequence extends ASequence implements SequenceI * @param curs * @return */ - protected int findIndex(int pos, SequenceCursor curs) + protected int findIndex(final int pos, SequenceCursor curs) { if (!isValidCursor(curs)) { @@ -851,10 +851,15 @@ public class Sequence extends ASequence implements SequenceI while (newPos != pos) { col += delta; // shift one column left or right - if (col < 0 || col == sequence.length) + if (col < 0) { break; } + if (col == sequence.length) + { + col--; // return last column if we failed to reach pos + break; + } if (!Comparison.isGap(sequence[col])) { newPos += delta; @@ -862,7 +867,14 @@ public class Sequence extends ASequence implements SequenceI } col++; // convert back to base 1 - updateCursor(pos, col, curs.firstColumnPosition); + + /* + * only update cursor if we found the target position + */ + if (newPos == pos) + { + updateCursor(pos, col, curs.firstColumnPosition); + } return col; }