Format changes
[jalview.git] / src / jalview / commands / EditCommand.java
index a53798a..83e4417 100644 (file)
@@ -99,6 +99,11 @@ public class EditCommand implements CommandI
     return edits==null?0:edits.length;\r
   }\r
 \r
+  public AlignmentI getAlignment()\r
+  {\r
+    return edits[0].al;\r
+  }\r
+\r
 \r
   public void appendEdit(String command,\r
                          SequenceI[] seqs,\r
@@ -200,11 +205,14 @@ public class EditCommand implements CommandI
 \r
     for(int i=0; i<command.seqs.length; i++)\r
     {\r
-      command.string[i] = command.seqs[i].getSequence(command.position,\r
-                                           command.position + command.number);\r
+      if(command.seqs[i].getLength()>command.position)\r
+      {\r
+        command.string[i] = command.seqs[i].getSequence(command.position,\r
+            command.position + command.number);\r
 \r
-      command.seqs[i].deleteChars(command.position,\r
-                                  command.position+command.number);\r
+        command.seqs[i].deleteChars(command.position,\r
+                                    command.position + command.number);\r
+      }\r
 \r
       if(command.seqs[i].getLength()<1)\r
       {\r
@@ -229,8 +237,20 @@ public class EditCommand implements CommandI
           command.al.addSequence(command.seqs[i]);\r
       }\r
       tmp = new StringBuffer(command.seqs[i].getSequence());\r
-      if(command.string!=null)\r
+\r
+      if(command.string!=null && command.string[i]!=null)\r
       {\r
+        if(command.position>=tmp.length())\r
+        {\r
+          //This occurs if padding is on, and residues\r
+          //are removed from end of alignment\r
+          int length = command.position-tmp.length();\r
+          while (length > 0)\r
+          {\r
+            tmp.append(command.gapChar);\r
+            length--;\r
+          }\r
+        }\r
         tmp.insert(command.position, command.string[i]);\r
         command.string[i] = null;\r
       }\r
@@ -270,6 +290,7 @@ public class EditCommand implements CommandI
          int number,\r
          AlignmentI al)\r
     {\r
+      this.gapChar = al.getGapCharacter();\r
       this.command = command;\r
       this.seqs = seqs;\r
       this.position = position;\r