PlainDocument.insertUpdate needs to explicitly handle the special case
of an insertion happening right after a newline. Apparently this worked
by accident before, and a recent patch that Lillian and I made to
GapContent exposed the weakness. This is fixed and committed now.
2006-01-09 Anthony Balkissoon <[EMAIL PROTECTED]>
* javax/swing/text/PlainDocument.java:
(insertUpdate): Handle special case of an insertion immediately
following a newline character.
--Tony
? include/gnu_java_net_PlainDatagramSocketImpl.h
? include/gnu_java_net_PlainSocketImpl.h
Index: javax/swing/text/PlainDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainDocument.java,v
retrieving revision 1.18
diff -u -r1.18 PlainDocument.java
--- javax/swing/text/PlainDocument.java 16 Nov 2005 18:31:42 -0000 1.18
+++ javax/swing/text/PlainDocument.java 9 Jan 2006 21:53:51 -0000
@@ -113,6 +113,46 @@
int elementIndex = rootElement.getElementIndex(offset);
Element firstElement = rootElement.getElement(elementIndex);
+ // If we're inserting immediately after a newline we have to fix the
+ // Element structure.
+ if (offset > 0)
+ {
+ try
+ {
+ String s = getText(offset - 1, 1);
+ if (s.equals("\n"))
+ {
+ int newEl2EndOffset = end;
+ boolean replaceNext = false;
+ if (rootElement.getElementCount() > elementIndex + 1)
+ {
+ replaceNext = true;
+ newEl2EndOffset =
+ rootElement.getElement(elementIndex + 1).getEndOffset();
+ }
+ Element newEl1 =
+ createLeafElement(rootElement, firstElement.getAttributes(),
+ firstElement.getStartOffset(), offset);
+ Element newEl2 =
+ createLeafElement (rootElement, firstElement.getAttributes(),
+ offset, newEl2EndOffset);
+ if (replaceNext)
+ rootElement.replace(elementIndex, 2, new Element[] { newEl1, newEl2 });
+ else
+ rootElement.replace(elementIndex, 1, new Element[] { newEl1, newEl2 });
+ firstElement = newEl2;
+ elementIndex ++;
+ }
+ }
+ catch (BadLocationException ble)
+ {
+ // This shouldn't happen.
+ AssertionError ae = new AssertionError();
+ ae.initCause(ble);
+ throw ae;
+ }
+ }
+
// added and removed are Element arrays used to add an ElementEdit
// to the DocumentEvent if there were entire lines added or removed.
Element[] removed = new Element[1];
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches