public static int calcRelativeCaretPosition(@NotNull Editor editor) {
    return ReadAction.compute(() -> {
      int caretY = editor.visualLineToY(editor.getCaretModel().getVisualPosition().line);
      int viewAreaPosition = editor.getScrollingModel().getVisibleAreaOnScrollingFinished().y;
      return caretY - viewAreaPosition;
    });
  }
public static int calcRelativeCaretPosition(@NotNull Editor editor)