nsIDOMNode* focusNode = GetFocusNode(); if (!focusNode) return NS_ERROR_FAILURE;  nsCOMPtr<nsIDOMRange> range; res = nsRepository::CreateInstance(kRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)); if (!NS_SUCCEEDED(res)) return res;    setAnchor(GetFocusNode(), GetFocusOffset()-1); res = range->SetStart(GetAnchorNode(), GetAnchorOffset()); if (!NS_SUCCEEDED(res)) return res; res = range->SetEnd(GetFocusNode(), GetFocusOffset()); if (!NS_SUCCEEDED(res)) return res;  res = AddItem(range); if (!NS_SUCCEEDED(res)) return res;
Extend(GetFocusNode(), GetFocusOffset() - 1);
nsRangeList::DeleteFromDocument(){  nsresult res;  // If we're already collapsed, then set ourselves to include the  // last item BEFORE the current range, rather than the range itself,  // before we do the delete.  PRBool isCollapsed;  IsCollapsed(&isCollapsed);  if (isCollapsed)  {    // If the offset is positive, then it's easy:    if (GetFocusOffset() > 0)    {      nsIDOMNode* focusNode = GetFocusNode();      if (!focusNode)        return NS_ERROR_FAILURE;      nsCOMPtr<nsIDOMRange> range;      res = nsRepository::CreateInstance(kRangeCID, nsnull,                                         kIDOMRangeIID,                                         getter_AddRefs(range));      if (!NS_SUCCEEDED(res))        return res;      // For some reason, this doesn't leave the anchor in the      // right place after the delete happens; it's point too far right.      setAnchor(GetFocusNode(), GetFocusOffset()-1);      res = range->SetStart(GetAnchorNode(), GetAnchorOffset());      if (!NS_SUCCEEDED(res))        return res;      res = range->SetEnd(GetFocusNode(), GetFocusOffset());      if (!NS_SUCCEEDED(res))        return res;      res = AddItem(range);      if (!NS_SUCCEEDED(res))        return res;    }    else    {      // Otherwise it's harder, have to find the previous node      return NS_ERROR_NOT_IMPLEMENTED;    }  }  // Get an iterator  nsRangeListIterator iter(this);  res = iter.First();  if (!NS_SUCCEEDED(res))    return res;  nsCOMPtr<nsIDOMRange> range;  while (iter.IsDone())  {    res = iter.CurrentItem(getter_AddRefs(range));    if (!NS_SUCCEEDED(res))      return res;    res = range->DeleteContents();    if (!NS_SUCCEEDED(res))      return res;    iter.Next();  }  // HACK: We need to reset the anchor and offset,  // in order for text insertion to work after a deletion.  Collapse(GetAnchorNode(), GetAnchorOffset());  return NS_OK;}