edits.add(new Edit(newBranch, 0, null, newLeaves));
    private void insertFracture(ElementSpec tag)    {      // 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();      int parentIndex = parent.getElementIndex(offset);            // This is the old paragraph.  We must remove all its children that       // occur after offset and move them to a new paragraph.  We must      // also recreate its child that occurs at offset to have the proper      // end offset.  The remainder of this child will also go in the new      // paragraph.      BranchElement previous = (BranchElement) parent.getElement(parentIndex);            // This is the new paragraph.      BranchElement newBranch =         (BranchElement) createBranchElement(parent, previous.getAttributes());                  // The steps we must take to properly fracture are:      // 1. Recreate the LeafElement at offset to have the correct end offset.      // 2. Create a new LeafElement with the remainder of the LeafElement in       //    #1 ==> this is whatever was in that LeafElement to the right of the      //    inserted newline.      // 3. Find the paragraph at offset and remove all its children that       //    occur _after_ offset.  These will be moved to the newly created      //    paragraph.      // 4. Move the LeafElement created in #2 and all the LeafElements removed      //    in #3 to the newly created paragraph.      // 5. Add the new paragraph to the parent.      int previousIndex = previous.getElementIndex(offset);      int numReplaced = previous.getElementCount() - previousIndex;      Element previousLeaf = previous.getElement(previousIndex);      AttributeSet prevLeafAtts = previous.getAttributes();            // This recreates the child at offset to have the proper end offset.        // (Step 1).      Element newPreviousLeaf =         createLeafElement(previous,                           prevLeafAtts, previousLeaf.getStartOffset(),                           offset);      // This creates the new child, which is the remainder of the old child.        // (Step 2).            Element firstLeafInNewBranch =         createLeafElement(newBranch, prevLeafAtts,                           offset, previousLeaf.getEndOffset());            // Now we move the new LeafElement and all the old children that occurred      // after the offset to the new paragraph.  (Step 4).      Element[] newLeaves = new Element[numReplaced];      newLeaves[0] = firstLeafInNewBranch;      for (int i = 1; i < numReplaced; i++)        newLeaves[i] = previous.getElement(previousIndex + i);      newBranch.replace(0, 0, newLeaves);      edits.add(new Edit(newBranch, 0, null, newLeaves));                  // Now we remove the children after the offset from the previous       // paragraph. (Step 3).      int removeSize = previous.getElementCount() - previousIndex;      Element[] add = new Element[] { newPreviousLeaf };      Element[] remove = new Element[removeSize];      for (int j = 0; j < removeSize; j++)        remove[j] = previous.getElement(previousIndex + j);      previous.replace(previousIndex, removeSize, add);      edits.add(new Edit(previous, previousIndex, remove, add));            // Finally we add the new paragraph to the parent. (Step 5).      Element[] nb = new Element[] { newBranch };      int index = parentIndex + 1;      parent.replace(index, 0, nb);      edits.add(new Edit(parent, index, null, nb));    }