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; }
/** * Scrolls the editor to place the given visual line in the middle of the current window. * * @param editor The editor to scroll * @param visualLine The visual line to place in the middle of the current window */ public static void scrollVisualLineToMiddleOfScreen(@NotNull Editor editor, int visualLine) { final ScrollingModel scrollingModel = editor.getScrollingModel(); int y = editor.visualLineToY(visualLine); int lineHeight = editor.getLineHeight(); int height = scrollingModel.getVisibleArea().height; scrollingModel.scrollVertically(y - ((height - lineHeight) / 2)); }
/** * Scrolls the editor to put the given visual line at the top of the current window. Ensures that any block inlay * elements above the given line are also visible. * * @param editor The editor to scroll * @param visualLine The visual line to place at the top of the current window * @return Returns true if the window was moved */ public static boolean scrollVisualLineToTopOfScreen(@NotNull final Editor editor, int visualLine) { final ScrollingModel scrollingModel = editor.getScrollingModel(); int inlayHeight = getHeightOfVisualLineInlays(editor, visualLine, true); int y = editor.visualLineToY(visualLine) - inlayHeight; int verticalPos = scrollingModel.getVerticalScrollOffset(); scrollingModel.scrollVertically(y); return verticalPos != scrollingModel.getVerticalScrollOffset(); }
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; }
private static int scrollFullPageUp(@NotNull final Editor editor, int pages) { final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); final int lineHeight = editor.getLineHeight(); int y = visibleArea.y; int topBound = visibleArea.y; int bottomBound = visibleArea.y + visibleArea.height; int line = 0; int caretLine = -1; // We know pages is negative for (int i = pages; i < 0; i++) { // E.g. a window showing 73-107 has page size 33. Scrolling up puts 74 at the bottom of the screen line = getFullVisualLine(editor, y, topBound, bottomBound) + 1; if (line == 1) { break; } y = editor.visualLineToY(line); bottomBound = y + lineHeight; topBound = bottomBound - visibleArea.height; y = topBound; caretLine = line; } scrollVisualLineToBottomOfScreen(editor, line); return caretLine; }
final ScrollingModel scrollingModel = editor.getScrollingModel(); final Rectangle visibleArea = scrollingModel.getVisibleArea(); final int caretScreenOffset = editor.visualLineToY(editor.getCaretModel().getVisualPosition().line) - visibleArea.y; final int yVisualLine = editor.visualLineToY(visualLine);
final ScrollingModel scrollingModel = editor.getScrollingModel(); int inlayHeight = getHeightOfVisualLineInlays(editor, visualLine, false); int y = editor.visualLineToY(visualLine); int verticalPos = scrollingModel.getVerticalScrollOffset(); int height = inlayHeight + editor.getLineHeight(); int topY = editor.visualLineToY(topVisualLine); if (topY - topLineInlayHeight + visibleArea.height < y + height) {
y = editor.visualLineToY(line); topBound = y; bottomBound = y + visibleArea.height;
final int yInitialCaret = editor.visualLineToY(caretModel.getVisualPosition().line); final int yTargetVisualLine = editor.visualLineToY(targetCaretVisualLine); if (Math.abs(yTargetVisualLine - yInitialCaret) > visibleArea.height) {