JAL-2842 JAL-2759 change to SeqPanel moveCursor
authorkiramt <k.mourao@dundee.ac.uk>
Wed, 22 Nov 2017 16:08:59 +0000 (16:08 +0000)
committerkiramt <k.mourao@dundee.ac.uk>
Wed, 22 Nov 2017 16:08:59 +0000 (16:08 +0000)
src/jalview/gui/SeqPanel.java

index e11af48..8b80ffd 100644 (file)
@@ -363,10 +363,25 @@ public class SeqPanel extends JPanel
       int original = seqCanvas.cursorX - dx;
       int maxWidth = av.getAlignment().getWidth();
 
-      while (!hidden.isVisible(seqCanvas.cursorX)
-              && seqCanvas.cursorX < maxWidth && seqCanvas.cursorX > 0)
+      if (!hidden.isVisible(seqCanvas.cursorX))
       {
-        seqCanvas.cursorX += dx;
+        int visx = hidden.findColumnPosition(seqCanvas.cursorX - dx);
+        int[] region = hidden.getRegionWithEdgeAtRes(visx);
+
+        if (region != null) // just in case
+        {
+          if (dx == 1)
+          {
+            // moving right
+            seqCanvas.cursorX = region[1] + 1;
+          }
+          else if (dx == -1)
+          {
+            // moving left
+            seqCanvas.cursorX = region[0] - 1;
+          }
+        }
+        seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
       }
 
       if (seqCanvas.cursorX >= maxWidth