@ApiStatus.Internal
  public static int calcSelectionEnd(Caret caret) {
    return caret.hasSelection() ? caret.getSelectionEnd() : caret.getOffset();
  }
@ApiStatus.Internal
  public static int calcSelectionEnd(Caret caret)