@Override
  public void setSelection(int startOffset, int endOffset) {
    if (startOffset < 0) startOffset = 0;
    if (endOffset < 0) endOffset = 0;
    // mimicking CaretImpl's doSetSelection: removing selection if startOffset == endOffset
    if (startOffset == endOffset) {
      myStart = myPos;
      myEnd = myPos;
      return;
    }

    if (startOffset > endOffset) {
      myStart = endOffset;
      myEnd = startOffset;
    } else {
      myStart = startOffset;
      myEnd = endOffset;
    }
    if (myPos < myStart) {
      myPos = myStart;
    }
    else if (myPos > myEnd) {
      myPos = myEnd;
    }
  }
@Override
  public void setSelection(int startOffset, int endOffset)