JAL-2759 Convert reveal to use cursor
[jalview.git] / src / jalview / datamodel / HiddenColumnsCursor.java
index b40afdf..2d579b0 100644 (file)
@@ -43,22 +43,15 @@ public class HiddenColumnsCursor
   /**
    * Set the cursor to a position
    * 
-   * @param first
-   *          absolute position of first hidden column
-   * @param last
-   *          absolute position of last hidden column
-   * @param index
-   *          index of last visited region
-   * @param hiddenCount
-   *          number of hidden columns before last visited region
+   * @param hiddenCols
    */
   protected void resetCursor(List<int[]> hiddenCols)
   {
     synchronized (this)
     {
+      hiddenColumns = hiddenCols;
       if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
       {
-        hiddenColumns = hiddenCols;
         firstColumn = hiddenColumns.get(0)[0];
         regionIndex = 0;
         hiddenSoFar = 0;
@@ -66,6 +59,31 @@ public class HiddenColumnsCursor
     }
   }
 
+  /**
+   * Delete the region the cursor is currently at. Avoids having to reset the
+   * cursor just because we deleted a region.
+   *
+   * @param hiddenCols
+   */
+  protected void updateForDeletedRegion(List<int[]> hiddenCols)
+  {
+
+    if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
+    {
+      // if there is a region to the right of the current region,
+      // nothing changes; otherwise
+      // we deleted the last region (index=hiddenCols.size()-1)
+      // or the index was at the end of the alignment (index=hiddenCols.size())
+      if (regionIndex >= hiddenColumns.size() - 1)
+      {
+        // deleted last region, index is now end of alignment
+        regionIndex = hiddenCols.size();
+      }
+    }
+
+    hiddenColumns = hiddenCols;
+  }
+
   protected void updateCursor(int index, int hiddenCount)
   {
     synchronized (this)