More small fixes to DefaultStyledDocument. The ChangeLog explains it
all. There are still some mauve regressions... almost there!

2006-01-23  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/text/DefaultStyledDocument.java
        (insertUpdate): Should only call createFracture with
        StartTagType. Added check.
        (insertContentTag): Should use the tags length for splitting.
        Also, added a check to determine if current's start and end 
        offset are equal to the offset and endOffset. If so, only one 
        leaf element should be added.
        (createFracture): Removed FIXME. This function is complete.
        (split): Added calls to replace. Changed so the child is
        added immediately to the paragraph. Prevents NPEs.

Index: javax/swing/text/DefaultStyledDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v
retrieving revision 1.45
diff -u -r1.45 DefaultStyledDocument.java
--- javax/swing/text/DefaultStyledDocument.java	23 Jan 2006 16:55:25 -0000	1.45
+++ javax/swing/text/DefaultStyledDocument.java	23 Jan 2006 20:17:57 -0000
@@ -690,7 +690,8 @@
     protected void insertUpdate(ElementSpec[] data)
     {
       int i = 0;
-      if (data[0].getType() == ElementSpec.ContentType)
+      int type = data[0].getType();
+      if (type == ElementSpec.ContentType)
         {
           // If the first tag is content we must treat it separately to allow
           // for joining properly to previous Elements and to ensure that
@@ -698,7 +699,7 @@
           i = 1;
           insertFirstContentTag(data);
         }
-      else
+      else if (type == ElementSpec.StartTagType)
         createFracture(data);
 
       // Handle each ElementSpec individually.
@@ -900,7 +901,8 @@
 
           Element[] added;
           Element[] removed = new Element[] { current };
-          Element[] splitRes = split(current, offset, length);
+          Element[] splitRes = split(current, offset, len);
+          
           if (splitRes[0] == null)
             {
               added = new Element[2];
@@ -910,13 +912,19 @@
               removed = new Element[0];
               index++;
             }
+          else if (current.getStartOffset() == offset && current.getEndOffset() == endOffset)
+            {
+              added = new Element[1];
+              added[0] = new LeafElement(paragraph, tagAtts, offset,
+                                           endOffset);
+            }
           else if (current.getStartOffset() == offset)
             {
               // This is if the new insertion happens immediately before
               // the <code>current</code> Element. In this case there are 2
               // resulting Elements.
               added = new Element[2];
-              added[0] = createLeafElement(paragraph, tagAtts, offset,
+              added[0] = new LeafElement(paragraph, tagAtts, offset,
                                            endOffset);
               added[1] = splitRes[1];
             }
@@ -927,7 +935,7 @@
               // 2 resulting Elements.
               added = new Element[2];
               added[0] = splitRes[0];
-              added[1] = createLeafElement(paragraph, tagAtts, offset,
+              added[1] = new LeafElement(paragraph, tagAtts, offset,
                                            endOffset);
             }
           else
@@ -937,7 +945,7 @@
               // there will be 3 resulting Elements.
               added = new Element[3];
               added[0] = splitRes[0];
-              added[1] = createLeafElement(paragraph, tagAtts, offset,
+              added[1] = new LeafElement(paragraph, tagAtts, offset,
                                            endOffset);
               added[2] = splitRes[1];
             }
@@ -954,9 +962,6 @@
      */
     private void createFracture(ElementSpec[] data)
     {
-      // FIXME: This method is not complete.  We must handle the elementStack
-      // properly and make sure the appropriate Elements are pushed onto the 
-      // top of the stack so future inserts go to the appropriate paragraph.
       BranchElement paragraph = (BranchElement)elementStack.peek();
       int index = paragraph.getElementIndex(offset);
       Element child = paragraph.getElement(index);
@@ -1004,7 +1009,7 @@
           Element[] newAdded;
 
           int count = el.getElementCount();
-          if (!(result[1] == null))
+          if (result[1] != null)
             {
               // This is the case when we can keep the first element.
               if (result[0] == null)
@@ -1033,11 +1038,12 @@
               Edit edit = getEditForParagraphAndIndex((BranchElement)el, index);
               edit.addRemovedElements(removed);
               edit.addAddedElements(added);
+              
               BranchElement newPar =
                 (BranchElement) new BranchElement(el.getParentElement(),
                                                     el.getAttributes());
-              Edit edit2 = getEditForParagraphAndIndex(newPar, 0);
-              edit2.addAddedElements(newAdded);
+              
+              newPar.replace(0, 0, newAdded);
               res = new Element[]{ null, newPar };
             }
           else
@@ -1046,14 +1052,15 @@
               for (int i = index; i < count; ++i)
                 removed[i - index] = el.getElement(i);
               added = new Element[0];
+              
               Edit edit = getEditForParagraphAndIndex((BranchElement)el, index);
               edit.addRemovedElements(removed);
               edit.addAddedElements(added);
+              
               BranchElement newPar =
                 (BranchElement) new BranchElement(el.getParentElement(),
                                                     el.getAttributes());
-              Edit edit2 = getEditForParagraphAndIndex(newPar, 0);
-              edit2.addAddedElements(removed);
+              newPar.replace(0, 0, removed);
               res = new Element[]{ null, newPar };
             }
         }
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to