public static void moveCaretToTextEnd(@NotNull Editor editor, @Nullable Project project) {
    editor.getCaretModel().removeSecondaryCarets();
    int offset = editor.getDocument().getTextLength();
    if (editor instanceof EditorImpl) {
      editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true));
    }
    else {
      editor.getCaretModel().moveToOffset(offset);
    }
    editor.getSelectionModel().removeSelection();

    ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.disableAnimation();
    scrollingModel.scrollToCaret(ScrollType.CENTER);
    scrollingModel.enableAnimation();

    if (project != null) {
      IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
      if (instance != null) {
        instance.includeCurrentCommandAsNavigation();
      }
    }
  }
public static void moveCaretToTextEnd(@NotNull Editor editor, @Nullable Project project)