private static int getFullVisualLine(@NotNull final Editor editor, int y, int topBound, int bottomBound) { int line = editor.yToVisualLine(y); int yActual = editor.visualLineToY(line); if (yActual < topBound) { line++; } else if (yActual + editor.getLineHeight() > bottomBound) { line--; } return line; }
public static int getVisualLineAtMiddleOfScreen(@NotNull final Editor editor) { final ScrollingModel scrollingModel = editor.getScrollingModel(); final Rectangle visibleArea = scrollingModel.getVisibleArea(); return editor.yToVisualLine(visibleArea.y + (visibleArea.height / 2)); }
private static int getScrollScreenTargetCaretVisualLine(@NotNull final Editor editor, int rawCount, boolean down) { final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); final int caretVisualLine = editor.getCaretModel().getVisualPosition().line; final int scrollOption = getScrollOption(rawCount); int targetCaretVisualLine; if (scrollOption == 0) { // Scroll up/down half window size by default. We can't use line count here because of block inlays final int offset = down ? (visibleArea.height / 2) : editor.getLineHeight() - (visibleArea.height / 2); targetCaretVisualLine = editor.yToVisualLine(editor.visualLineToY(caretVisualLine) + offset); } else { targetCaretVisualLine = down ? caretVisualLine + scrollOption : caretVisualLine - scrollOption; } return targetCaretVisualLine; }
int topVisualLine = editor.yToVisualLine(y - visibleArea.height + height); int topLineInlayHeight = getHeightOfVisualLineInlays(editor, topVisualLine, true); int topY = editor.visualLineToY(topVisualLine);
targetCaretVisualLine = editor.yToVisualLine(yInitialCaret + scrollingModel.getVisibleArea().y - yPrevious);