Index: javax/swing/text/AbstractDocument.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/AbstractDocument.java,v retrieving revision 1.30 diff -u -r1.30 AbstractDocument.java --- javax/swing/text/AbstractDocument.java 28 Sep 2005 20:11:10 -0000 1.30 +++ javax/swing/text/AbstractDocument.java 4 Oct 2005 19:21:19 -0000 @@ -519,8 +519,30 @@ DefaultDocumentEvent event = new DefaultDocumentEvent(offset, text.length(), DocumentEvent.EventType.INSERT); - content.insertString(offset, text); + + UndoableEdit temp = content.insertString(offset, text); + GapContent.UndoInsertString changes = null; + if (content instanceof GapContent) + changes = (GapContent.UndoInsertString) temp; insertUpdate(event, attributes); + + if (changes != null) + { + // We need to add an ElementChange to our DocumentEvent + // so let's set up the parameters + Element root = getDefaultRootElement(); + 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); + } fireInsertUpdate(event); } @@ -595,9 +617,11 @@ new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.REMOVE); removeUpdate(event); + boolean shouldFire = content.getString(offset, length).length() != 0; content.remove(offset, length); postRemoveUpdate(event); - fireRemoveUpdate(event); + if (shouldFire) + fireRemoveUpdate(event); } /** @@ -1775,7 +1799,7 @@ return (DocumentEvent.ElementChange) changes.get(elem); } } - + /** * An implementation of address@hidden DocumentEvent.ElementChange} to be added * to address@hidden DefaultDocumentEvent}s. Index: javax/swing/text/GapContent.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v retrieving revision 1.28 diff -u -r1.28 GapContent.java --- javax/swing/text/GapContent.java 30 Sep 2005 14:38:02 -0000 1.28 +++ javax/swing/text/GapContent.java 4 Oct 2005 19:21:19 -0000 @@ -44,6 +44,9 @@ import java.util.ListIterator; import java.util.Vector; +import javax.swing.undo.AbstractUndoableEdit; +import javax.swing.undo.CannotRedoException; +import javax.swing.undo.CannotUndoException; import javax.swing.undo.UndoableEdit; /** @@ -126,6 +129,45 @@ } } + class UndoInsertString extends AbstractUndoableEdit + { + public int where, length; + String text; + public UndoInsertString(int start, int len) + { + where = start; + length = len; + } + + public void undo () throws CannotUndoException + { + super.undo(); + try + { + text = getString(where, length); + remove(where, length); + } + catch (BadLocationException ble) + { + throw new CannotUndoException(); + } + } + + public void redo () throws CannotUndoException + { + super.redo(); + try + { + insertString(where, text); + } + catch (BadLocationException ble) + { + throw new CannotRedoException(); + } + } + + } + /** The serialization UID (compatible with JDK1.5). */ private static final long serialVersionUID = -6226052713477823730L; @@ -234,9 +276,9 @@ throw new BadLocationException("the where argument cannot be greater" + " than the content length", where); - replace(where, 0, str.toCharArray(), str.length()); + replace(where, 0, str.toCharArray(), strLen); - return null; + return new UndoInsertString(where, strLen); } /** Index: javax/swing/text/JTextComponent.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/JTextComponent.java,v retrieving revision 1.39 diff -u -r1.39 JTextComponent.java --- javax/swing/text/JTextComponent.java 4 Oct 2005 15:10:54 -0000 1.39 +++ javax/swing/text/JTextComponent.java 4 Oct 2005 19:21:20 -0000 @@ -1018,8 +1018,13 @@ { try { - doc.remove(0, doc.getLength()); - doc.insertString(0, text, null); + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).replace(0, doc.getLength(), text, null); + else + { + doc.remove(0, doc.getLength()); + doc.insertString(0, text, null); + } } catch (BadLocationException e) { Index: javax/swing/text/PlainView.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v retrieving revision 1.13 diff -u -r1.13 PlainView.java --- javax/swing/text/PlainView.java 3 Oct 2005 20:02:57 -0000 1.13 +++ javax/swing/text/PlainView.java 4 Oct 2005 19:21:20 -0000 @@ -62,6 +62,9 @@ /** The length of the longest line in the Document **/ float maxLineLength = -1; + /** The longest line in the Document **/ + Element longestLine = null; + protected FontMetrics metrics; public PlainView(Element elem) @@ -237,7 +240,11 @@ { } int width = metrics.charsWidth(seg.array, seg.offset, seg.count); - span = Math.max(span, width); + if (width > span) + { + longestLine = child; + span = width; + } } maxLineLength = span; return maxLineLength;