removed = new Element[] { current };
    private void insertContentTag(ElementSpec tag)    {      prepareContentInsertion();      int len = tag.getLength();      int dir = tag.getDirection();      if (dir == ElementSpec.JoinPreviousDirection)        {          // The mauve tests to this class show that a JoinPrevious insertion          // does not add any edits to the document event. To me this means          // that nothing is done here. The previous element naturally should          // expand so that it covers the new characters.        }      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);          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);        }      else        {          BranchElement paragraph = (BranchElement) elementStack.peek();          int index = paragraph.getElementIndex(offset);          Element current = paragraph.getElement(index);          Element[] added;          Element[] removed;          Element[] splitRes = split(current, offset, length);          // Special case for when offset == startOffset or offset == endOffset.          if (splitRes[0] == null)            {              added = new Element[2];              added[0] = createLeafElement(paragraph, tag.getAttributes(),                                           offset, offset + length);              added[1] = splitRes[1];              removed = new Element[0];              index++;            }          else if (current.getStartOffset() == offset)            {              added = new Element[2];              added[0] = createLeafElement(paragraph, tag.getAttributes(),                                           offset, offset + length);              added[1] = splitRes[1];              removed = new Element[] { current };            }          else if (current.getEndOffset() - length == offset)            {              added = new Element[2];              added[0] = splitRes[0];              added[1] = createLeafElement(paragraph, tag.getAttributes(),                                           offset, offset + length);              removed = new Element[] { current };            }          else            {              added = new Element[3];              added[0] = splitRes[0];              added[1] = createLeafElement(paragraph, tag.getAttributes(),                                           offset, offset + length);              added[2] = splitRes[1];              removed = new Element[] { current };            }          paragraph.replace(index, removed.length, added);          addEdit(paragraph, index, removed, added);        }      offset += len;    }