int j = firstElement.getStartOffset(); int i = str.indexOf('\n', offset); while (i != -1 && i <= end) {  elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY, j, i + 1)); j = i + 1; if (j >= str.length()) break; i = str.indexOf('\n', j); }    if (elts.size() != 0) {   added = new Element[elts.size()]; for (int k = 0; k < elts.size(); ++k) added[k] = (Element) elts.get(k); removed[0] = firstElement;   ElementEdit e = new ElementEdit(rootElement, elementIndex, removed, added); event.addEdit(e);   ((BranchElement) rootElement).replace(elementIndex, 1, added); } } catch (BadLocationException e) {  AssertionError ae = new AssertionError(); ae.initCause(e); throw ae; }
  protected void insertUpdate(DefaultDocumentEvent event, AttributeSet attributes)  {    reindex();    super.insertUpdate(event, attributes);  }