((BranchElement) el).replace(index, removed.length, added); edits.add(new Edit(el, index, removed, added));
Edit edit = getEditForParagraphAndIndex((BranchElement)el, index); edit.addRemovedElements(removed); edit.addAddedElements(added);
    private Element[] split(Element el, int offset, int space)    {      // If we are at an element boundary, then return an empty array.      if ((offset == el.getStartOffset() || offset == el.getEndOffset())          && space == 0 && el.isLeaf())        return new Element[2];      // If the element is an instance of BranchElement, then we recursivly      // call this method to perform the split.      Element[] res = new Element[2];      if (el instanceof BranchElement)        {          int index = el.getElementIndex(offset);          Element child = el.getElement(index);          Element[] result = split(child, offset, space);          Element[] removed;          Element[] added;          Element[] newAdded;          int count = el.getElementCount();          if (!(result[1] == null))            {              // This is the case when we can keep the first element.              if (result[0] == null)                {                  removed = new Element[count - index - 1];                  newAdded = new Element[count - index - 1];                  added = new Element[]{};		}              // This is the case when we may not keep the first element.              else                {                  removed = new Element[count - index];                  newAdded = new Element[count - index];                  added = new Element[]{result[0]};                }              newAdded[0] = result[1];              for (int i = index; i < count; i++)                {                  Element el2 = el.getElement(i);                  int ind = i - count + removed.length;                  removed[ind] = el2;                  if (ind != 0)                    newAdded[ind] = el2;                }              ((BranchElement) el).replace(index, removed.length, added);              edits.add(new Edit(el, index, removed, added));              BranchElement newPar =                (BranchElement) createBranchElement(el.getParentElement(),                                                    el.getAttributes());              newPar.replace(0, 0, newAdded);              res = new Element[]{ null, newPar };	}      else            {              removed = new Element[count - index];              for (int i = index; i < count; ++i)                removed[i - index] = el.getElement(i);              added = new Element[0];              ((BranchElement) el).replace(index, removed.length,                                           added);              edits.add(new Edit(el, index, removed, added));              BranchElement newPar =                (BranchElement) createBranchElement(el.getParentElement(),                                                    el.getAttributes());              newPar.replace(0, 0, removed);              res = new Element[]{ null, newPar };            }        }      else if (el instanceof LeafElement)        {          BranchElement par = (BranchElement) el.getParentElement();          Element el1 = createLeafElement(par, el.getAttributes(),                                          el.getStartOffset(), offset);          Element el2 = createLeafElement(par, el.getAttributes(),                                          offset + space, el.getEndOffset());          res = new Element[]{ el1, el2 };        }      return res;    }