@Override
  public void moveToOffset(int offset, boolean locateBeforeSoftWrap) {
    JTextComponent textComponent = getTextComponent();
    int targetOffset = Math.min(offset, textComponent.getText().length());
    int currentPosition = textComponent.getCaretPosition();
    // We try to preserve selection, to match EditorImpl behaviour.
    // It's only possible though, if target offset is located at either end of existing selection.
    if (targetOffset != currentPosition) {
      if (targetOffset == textComponent.getCaret().getMark()) {
        textComponent.setCaretPosition(currentPosition);
        textComponent.moveCaretPosition(targetOffset);
      }
      else {
        textComponent.setCaretPosition(targetOffset);
      }
    }
  }
@Override
  public void moveToOffset(int offset, boolean locateBeforeSoftWrap)