static int fitLineToEditor(@NotNull EditorImpl editor, int visualLine) {
    int lineCount = editor.getVisibleLineCount();
    int shift = 0;
    if (visualLine >= lineCount - 1) {
      CharSequence sequence = editor.getDocument().getCharsSequence();
      shift = sequence.isEmpty() ? 0 : sequence.charAt(sequence.length() - 1) == '\n' ? 1 : 0;
    }
    return Math.max(0, Math.min(lineCount - shift, visualLine));
  }
static int fitLineToEditor(@NotNull EditorImpl editor, int visualLine)