These changes to DefaultStyledDocument make all the local tests I have here pass. I will commit these tests to Mauve now. The number one outstanding problem with DefaultStyledDocument and ElementBuffer is the way DocumentEvents are handled and marked up. Lillian is working on that right now, hopefully we can have it sorted out before too long.
2006-01-11 Anthony Balkissoon <[EMAIL PROTECTED]> * javax/swing/text/DefaultStyledDocument.java: (ElementBuffer.insertContentTag): Don't adjust the structure here. This will have been taken care of in insertFracture. Added a comment explaining that we need to add edits to the DocumentEvent and that this may be the place to do it. --Tony
Index: javax/swing/text/DefaultStyledDocument.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v retrieving revision 1.30 diff -u -r1.30 DefaultStyledDocument.java --- javax/swing/text/DefaultStyledDocument.java 11 Jan 2006 20:07:24 -0000 1.30 +++ javax/swing/text/DefaultStyledDocument.java 11 Jan 2006 20:34:36 -0000 @@ -798,14 +798,19 @@ curr.getAttributes(), curr.getStartOffset(), offset); Element grandParent = parent.getParentElement(); - BranchElement nextBranch = (BranchElement) grandParent.getElement(grandParent.getElementIndex(parent.getEndOffset())); + BranchElement nextBranch = + (BranchElement) grandParent.getElement + (grandParent.getElementIndex(parent.getEndOffset())); Element firstLeaf = nextBranch.getElement(0); while (!firstLeaf.isLeaf()) { firstLeaf = firstLeaf.getElement(0); } BranchElement parent2 = (BranchElement) firstLeaf.getParentElement(); - Element newEl2 = createLeafElement(parent2, firstLeaf.getAttributes(), offset, firstLeaf.getEndOffset()); + Element newEl2 = + createLeafElement(parent2, + firstLeaf.getAttributes(), + offset, firstLeaf.getEndOffset()); parent2.replace(0, 1, new Element[] { newEl2 }); @@ -941,6 +946,9 @@ */ private void insertFracture(ElementSpec tag) { + System.out.println ("BEFORE FRACTURE:"); + printElements(getDefaultRootElement(), 0); + // This is the parent of the paragraph about to be fractured. We will // create a new child of this parent. BranchElement parent = (BranchElement) elementStack.peek(); @@ -1007,6 +1015,9 @@ parent.replace(parentIndex + 1, 0, new Element[] { newBranch }); // FIXME: Add the edits to the DocumentEvent via the addEdit method. + + System.out.println ("AFTER FRACTURE:"); + printElements(getDefaultRootElement(), 0); } /** @@ -1029,28 +1040,10 @@ } else if (dir == ElementSpec.JoinNextDirection) { - BranchElement paragraph = (BranchElement) elementStack.peek(); - int currentIndex = paragraph.getElementIndex(offset); - Element current = paragraph.getElement(currentIndex); - Element next = paragraph.getElement(currentIndex + 1); - - if (next == null) - return; - - Element newEl1 = createLeafElement(paragraph, - current.getAttributes(), - current.getStartOffset(), - offset); - Element newEl2 = createLeafElement(paragraph, - current.getAttributes(), - offset, - next.getEndOffset()); - - Element[] add = new Element[] { newEl1, newEl2 }; - Element[] remove = new Element[] { current, next }; - paragraph.replace(currentIndex, 2, add); - // Add this action to the document event. - addEdit(paragraph, currentIndex, remove, add); + // Doing nothing here gives us the proper structure. + // However, edits must be added to the document event. + // It is possible these should happen here, or also possible that + // they should happen in insertFracture. } else if (dir == ElementSpec.OriginateDirection) {
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches