if (children[index + 1].getStartOffset() > offset) { if ((offset - elem.getEndOffset()) > (children[index + 1].getStartOffset() - offset)) return index + 1; else return index; }
    public int getElementIndex(int offset)    {      // If we have no children, return -1.      if (getElementCount() == 0)        return - 1;      // XXX: There is surely a better algorithm      // as beginning from first element each time.      for (int index = 0; index < children.length; ++index)        {          Element elem = children[index];          if ((elem.getStartOffset() <= offset)               && (offset < elem.getEndOffset()))            return index;        }      // If offset is greater than the index of the last element, return      // the index of the last element.      return getElementCount() - 1;    }