Very sorry, but my PlainDocument patch yesterday caused some regressions
in text components that use PlainDocument.  Yesterday's patch had the
performance improvement of not having to look through the entire
document to index all of the lines every time text is inserted.
Instead, we only look at the range where the text was inserted to look
for new lines to index.  However, if we find any newlines, the very
first new Element we add doesn't start at the point of insertion, it
starts at the beginning of the line where text was inserted.  This is
fixed now.


2005-11-16  Anthony Balkissoon  <[EMAIL PROTECTED]>

        * javax/swing/text/PlainDocument.java:
        (insertUpdate): The very first new element added doesn't start at the 
        start of the event, it starts at the start offset of the Element that
        contains the start of the event.

--Tony
Index: javax/swing/text/PlainDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainDocument.java,v
retrieving revision 1.16
diff -u -r1.16 PlainDocument.java
--- javax/swing/text/PlainDocument.java	15 Nov 2005 19:45:46 -0000	1.16
+++ javax/swing/text/PlainDocument.java	16 Nov 2005 16:30:03 -0000
@@ -111,6 +111,7 @@
     int offset = event.getOffset();
     int end = offset + event.getLength();
     int elementIndex = rootElement.getElementIndex(offset);
+    Element firstElement = rootElement.getElement(elementIndex);
     
     // added and removed are Element arrays used to add an ElementEdit
     // to the DocumentEvent if there were entire lines added or removed.
@@ -123,8 +124,8 @@
 
         // Determine how many NEW lines were added by finding the newline
         // characters within the newly inserted text
-        int j = offset;
-        int i = str.indexOf('\n', j);
+        int j = firstElement.getStartOffset();
+        int i = str.indexOf('\n', offset);
         while (i != -1 && i <= end)
           {            
             // For each new line, create a new element
@@ -145,7 +146,7 @@
             added = new Element[elts.size()];
             for (int k = 0; k < elts.size(); ++k)
               added[k] = (Element) elts.get(k);
-            removed[0] = rootElement.getElement(elementIndex);
+            removed[0] = firstElement;
             
             // Now create and add the ElementEdit
             ElementEdit e = new ElementEdit(rootElement, elementIndex, removed,
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to