Fixed bug in trim right annotation adjust
[jalview.git] / src / jalview / commands / EditCommand.java
index f3b178f..7effdfb 100644 (file)
@@ -357,7 +357,7 @@ public class EditCommand implements CommandI
       if(!insert)\r
         command.deletedAnnotations = new Hashtable();\r
 \r
-      int aSize, tSize;\r
+      int aSize;\r
       Annotation [] temp;\r
       for (int a = 0; a < annotations.length; a++)\r
       {\r
@@ -368,11 +368,19 @@ public class EditCommand implements CommandI
 \r
         aSize = annotations[a].annotations.length;\r
         if(insert)\r
-          tSize = aSize + command.number;\r
+          temp = new Annotation[aSize + command.number];\r
         else\r
-          tSize = aSize - command.number;\r
-\r
-        temp = new Annotation[tSize];\r
+        {\r
+          if(command.position<aSize)\r
+          {\r
+            if (aSize - command.number + command.position > 0)\r
+              temp = new Annotation[aSize - command.number + command.position];\r
+            else\r
+              temp = new Annotation[aSize];\r
+          }\r
+          else\r
+            temp = new Annotation[aSize];\r
+        }\r
 \r
         if(insert)\r
         {\r
@@ -406,7 +414,7 @@ public class EditCommand implements CommandI
         }\r
         else\r
         {\r
-          if(command.position < annotations[a].annotations.length)\r
+          if(command.position < aSize &&  aSize - command.number+command.position>0)\r
           {\r
             System.arraycopy(annotations[a].annotations,\r
                              0, temp, 0, command.position);\r