int startParagraph = root.getElementIndex(offset); int endParagraph = root.getElementIndex(offset + length); Element[] empty = new Element[0]; int removeStart = -1; int removeEnd = -1; for (int i = startParagraph;  i < endParagraph; i++) { BranchElement paragraph = (BranchElement) root.getElement(i); int contentStart = paragraph.getElementIndex(offset); int contentEnd = paragraph.getElementIndex(offset + length); if (contentStart == paragraph.getStartOffset() && contentEnd == paragraph.getEndOffset()) {    if (removeStart == -1) { removeStart = i; removeEnd = i; } else removeEnd = i; } else {   int removeLen = contentEnd - contentStart; Element[] removed = new Element[removeLen]; for (int j = contentStart; j < contentEnd; j++) removed[j] = paragraph.getElement(j); Edit edit = getEditForParagraphAndIndex(paragraph, contentStart); edit.addRemovedElements(removed); } }   if (removeStart != -1) { int removeLen = removeEnd - removeStart; Element[] removed = new Element[removeLen]; for (int i = removeStart; i < removeEnd; i++) removed[i] = root.getElement(i); Edit edit = getEditForParagraphAndIndex((BranchElement) root, removeStart); edit.addRemovedElements(removed); }
removeElements(root, offset, endOffset);
    protected void removeUpdate()    {      int startParagraph = root.getElementIndex(offset);      int endParagraph = root.getElementIndex(offset + length);      Element[] empty = new Element[0];      int removeStart = -1;      int removeEnd = -1;      for (int i = startParagraph;  i < endParagraph; i++)        {          BranchElement paragraph = (BranchElement) root.getElement(i);          int contentStart = paragraph.getElementIndex(offset);          int contentEnd = paragraph.getElementIndex(offset + length);          if (contentStart == paragraph.getStartOffset()              && contentEnd == paragraph.getEndOffset())            {              // In this case we only need to remove the whole paragraph. We              // do this in one go after this loop and only record the indices              // here.              if (removeStart == -1)                {                  removeStart = i;                  removeEnd = i;                }              else                removeEnd = i;            }          else            {              // In this case we remove a couple of child elements from this              // paragraph.              int removeLen = contentEnd - contentStart;              Element[] removed = new Element[removeLen];              for (int j = contentStart; j < contentEnd; j++)                removed[j] = paragraph.getElement(j);              Edit edit = getEditForParagraphAndIndex(paragraph, contentStart);              edit.addRemovedElements(removed);            }        }      // Now we remove paragraphs from the root that have been tagged for      // removal.      if (removeStart != -1)        {          int removeLen = removeEnd - removeStart;          Element[] removed = new Element[removeLen];          for (int i = removeStart; i < removeEnd; i++)            removed[i] = root.getElement(i);          Edit edit = getEditForParagraphAndIndex((BranchElement) root,                                                  removeStart);          edit.addRemovedElements(removed);        }    }