Merge remote-tracking branch 'origin/bug/JAL-2742' into
[jalview.git] / src / jalview / datamodel / CigarArray.java
index d90b3cd..2aa3efb 100644 (file)
@@ -172,35 +172,29 @@ public class CigarArray extends CigarBase
         hideStart = region[0];
         hideEnd = region[1];
 
-        // edit hidden regions to selection range
-        // TODO possible bug here in original code: if hideEnd==last we continue
-        // but shouldn't this be a single D at start?
-        if (hideStart < last)
+        // just move on if hideEnd is before last
+        if (hideEnd < last)
         {
-          if (hideEnd > last)
-          {
-            hideStart = last;
-          }
-          else
-          {
-            continue;
-          }
+          continue;
         }
-
+        // exit if next region is after end
         if (hideStart > end)
         {
           break;
         }
 
-        if (hideEnd > end)
+        // truncate region at start if last falls in region
+        if ((hideStart < last) && (hideEnd >= last))
         {
-          hideEnd = end;
+          hideStart = last;
         }
 
-        if (hideStart > hideEnd)
+        // truncate region at end if end falls in region
+        if (hideEnd > end) // already checked that hideStart<=end
         {
-          break;
+          hideEnd = end;
         }
+
         /**
          * form operations...
          */
@@ -213,7 +207,7 @@ public class CigarArray extends CigarBase
       }
 
       // Final match if necessary.
-      if (last < end)
+      if (last <= end)
       {
         addOperation(CigarArray.M, end - last + 1);
       }