Small fix to AbstractDocument's insertString and remove methods fixes
the bug I mentioned in my last post.  The DocumentEvents now don't
include ElementChanges unless Elements were added or removed.

I'll turn the testcase I worked on into a Mauve testcase and submit it.

2005-10-12  Anthony Balkissoon  <[EMAIL PROTECTED]>

        * javax/swing/text/AbstractDocument.java:
        (insertString): Don't include an ElementChange if no children were
        added.
        (remove): Don't include an ElementChange if no children were removed.

--Tony
Index: javax/swing/text/AbstractDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/AbstractDocument.java,v
retrieving revision 1.33
diff -u -r1.33 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java	6 Oct 2005 19:53:33 -0000	1.33
+++ javax/swing/text/AbstractDocument.java	12 Oct 2005 18:03:37 -0000
@@ -557,14 +557,20 @@
         int start = root.getElementIndex(changes.where);
         int end = root.getElementIndex(changes.where+changes.length);
 
-        Element[] removed = new Element[1];
-        removed[0] = root;
-        Element[] added = new Element[end - start + 1];
-        for (int i = start; i <= end; i++)
-          added[i - start] = root.getElement(i);
-    
-        ElementEdit edit = new ElementEdit(root, root.getElementIndex(changes.where), removed, added);    
-        event.addEdit(edit);
+        if (!(start == 0 && end == 0))
+          {
+            Element[] removed = new Element[1];
+            removed[0] = root;
+            Element[] added = new Element[end - start + 1];
+            for (int i = start; i <= end; i++)
+              added[i - start] = root.getElement(i);
+
+            ElementEdit edit = new ElementEdit(
+                                               root,
+                                               root.getElementIndex(changes.where),
+                                               removed, added);
+            event.addEdit(edit);
+          }
       }
     fireInsertUpdate(event);
   }
@@ -718,7 +724,7 @@
     if (content instanceof GapContent)
       changes = (GapContent.UndoRemove) temp;
 
-    if (changes != null)
+    if (changes != null && !(start == end))
       {
         // We need to add an ElementChange to our DocumentEvent
         ElementEdit edit = new ElementEdit (root, start, removed, added);
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to