JAL-2822 stash start/end before setSequence (which will modify ‘end’) and catch cases...
authorJim Procter <jprocter@issues.jalview.org>
Thu, 16 Nov 2017 16:30:52 +0000 (16:30 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 16 Nov 2017 16:33:32 +0000 (16:33 +0000)
src/jalview/commands/EditCommand.java

index 06f59cb..894dc75 100644 (file)
@@ -776,6 +776,10 @@ public class EditCommand implements CommandI
       {
         tmp.append(oldstring.substring(end));
       }
+      // stash end prior to updating the sequence object so we can save it if
+      // need be.
+      Range oldstartend = new Range(command.seqs[i].getStart(),
+              command.seqs[i].getEnd());
       command.seqs[i].setSequence(tmp.toString());
       command.string[i] = oldstring
               .substring(start, Math.min(end, oldstring.length()))
@@ -785,25 +789,27 @@ public class EditCommand implements CommandI
 
       if (!nogaprep.toLowerCase().equals(nogapold.toLowerCase()))
       {
-        // probably need a new dataset sequence
-        if (newDSWasNeeded)
+        // we may already have dataset and limits stashed...
+        if (newDSWasNeeded || newStartEndWasNeeded)
         {
+          if (newDSWasNeeded)
+          {
           // then just switch the dataset sequence
           SequenceI oldds = command.seqs[i].getDatasetSequence();
           command.seqs[i].setDatasetSequence(command.oldds[i]);
           command.oldds[i] = oldds;
-        }
-        else
-        if (newStartEndWasNeeded)
-        {
-          Range newStart = command.oldStartEnd[i];
-          command.oldStartEnd[i] = new Range(command.seqs[i].getStart(),
-                  command.seqs[i].getEnd());
-          command.seqs[i].setStart(newStart.getBegin());
-          command.seqs[i].setEnd(newStart.getEnd());
+          }
+          if (newStartEndWasNeeded)
+          {
+            Range newStart = command.oldStartEnd[i];
+            command.oldStartEnd[i] = oldstartend;
+            command.seqs[i].setStart(newStart.getBegin());
+            command.seqs[i].setEnd(newStart.getEnd());
+          }
         }
         else         
         {
+          // decide if we need a new dataset sequence or modify start/end
           // first edit the original dataset sequence string
           SequenceI oldds = command.seqs[i].getDatasetSequence();
           String osp = oldds.getSequenceAsString();
@@ -846,7 +852,8 @@ public class EditCommand implements CommandI
             {
               // modification at end
               command.seqs[i].setEnd(
-                      beforeEditedPositions.getEnd() + nogaprep.length());
+                      beforeEditedPositions.getEnd() + nogaprep.length()
+                              - nogapold.length());
             }
             else if (afterEditedPositions != null
                     && beforeEditedPositions == null)