This fixes a couple of the mauve regressions that were caused by some of
the latest changes. This prevents a fracture from occurring when a
string is inserted with a newline at the end.

2006-12-12  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/text/DefaultStyledDocument.java
        (insertUpdate): Added check to check if attribute set is
        empty.
        (insertUpdate): Added check to determine if last character
        is a newline. If it is, we should not be fracturing.
        (insert): Added check to determine if attribute set is empty.
        If it is, insertUpdate should not be called.

Index: javax/swing/text/DefaultStyledDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v
retrieving revision 1.32
diff -u -r1.32 DefaultStyledDocument.java
--- javax/swing/text/DefaultStyledDocument.java	11 Jan 2006 20:56:04 -0000	1.32
+++ javax/swing/text/DefaultStyledDocument.java	12 Jan 2006 21:41:16 -0000
@@ -1671,7 +1671,7 @@
   {
     super.insertUpdate(ev, attr);
     // If the attribute set is null, use an empty attribute set.
-    if (attr == null)
+    if (attr == null || attr.getAttributeCount() == 0)
       attr = SimpleAttributeSet.EMPTY;
     int offset = ev.getOffset();
     int length = ev.getLength();
@@ -1759,11 +1759,25 @@
     // If we are inserting after a newline then this value comes from 
     // handleInsertAfterNewline.
     if (finalStartTag != null)
-      {
+      {        
         if (prevCharWasNewline)
           finalStartTag.setDirection(finalStartDirection);
         else if (prevParagraph.getEndOffset() != endOffset)
-          finalStartTag.setDirection(ElementSpec.JoinFractureDirection);
+          {
+            try
+              {
+                String last = getText(endOffset - 1, 1);
+                if (!last.equals("\n"))
+                  finalStartTag.setDirection(ElementSpec.JoinFractureDirection);
+              }
+            catch (BadLocationException ble)
+              {
+                // This shouldn't happen.
+                AssertionError ae = new AssertionError();
+                ae.initCause(ble);
+                throw ae;
+              } 
+          }
         else
           {
             // If there is an element AFTER this one, then set the 
@@ -1958,7 +1972,7 @@
           {
             ElementSpec spec = data[i];
             AttributeSet atts = spec.getAttributes();
-            if (atts != null)
+            if (atts != null && atts.getAttributeCount() != 0)
               insertUpdate(ev, atts);
           }        
 
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to