From: Jim Procter Date: Thu, 16 Nov 2017 16:30:52 +0000 (+0000) Subject: JAL-2822 stash start/end before setSequence (which will modify ‘end’) and catch cases... X-Git-Tag: Release_2_11_1_0~98^2~11 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f7b3f09efa23c9353afee3ad7f57c61ab2560e41;p=jalview.git JAL-2822 stash start/end before setSequence (which will modify ‘end’) and catch cases when dataset sequence and start/end limits change --- diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 06f59cb..894dc75 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -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)