/** * Gets the number of characters that are visible on a screen line * * @param editor The editor * @return The number of screen columns */ public static int getScreenWidth(@NotNull final Editor editor) { Rectangle rect = editor.getScrollingModel().getVisibleArea(); Point pt = new Point(rect.width, 0); VisualPosition vp = editor.xyToVisualPosition(pt); return vp.column; }
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)); }
public static int getVisualLineAtTopOfScreen(@NotNull final Editor editor) { final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); return getFullVisualLine(editor, visibleArea.y, visibleArea.y, visibleArea.y + visibleArea.height); }
public static int getVisualLineAtBottomOfScreen(@NotNull final Editor editor) { final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); return getFullVisualLine(editor, visibleArea.y + visibleArea.height, visibleArea.y, visibleArea.y + visibleArea.height); }
/** * Gets the number of pixels per column of text. * * @param editor The editor * @return The number of pixels */ public static int getColumnWidth(@NotNull final Editor editor) { Rectangle rect = editor.getScrollingModel().getVisibleArea(); if (rect.width == 0) return 0; Point pt = new Point(rect.width, 0); VisualPosition vp = editor.xyToVisualPosition(pt); if (vp.column == 0) return 0; return rect.width / vp.column; }
/** * Gets the number of lines than can be displayed on the screen at one time. This is rounded down to the * nearest whole line if there is a partial line visible at the bottom of the screen. * * Note that this value is only approximate and should be avoided whenever possible! * * @param editor The editor * @return The number of screen lines */ private static int getApproximateScreenHeight(@NotNull final Editor editor) { int lh = editor.getLineHeight(); int height = editor.getScrollingModel().getVisibleArea().y + editor.getScrollingModel().getVisibleArea().height - getVisualLineAtTopOfScreen(editor) * lh; return height / lh; }
/** * 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)); }
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; }
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 scrollFullPageDown(@NotNull final Editor editor, int pages) { final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); final int lineCount = getVisualLineCount(editor);
final Rectangle visibleArea = scrollingModel.getVisibleArea(); final int caretScreenOffset = editor.visualLineToY(editor.getCaretModel().getVisualPosition().line) - visibleArea.y;
final Rectangle visibleArea = scrollingModel.getVisibleArea(); targetCaretVisualLine = editor.yToVisualLine(yInitialCaret + scrollingModel.getVisibleArea().y - yPrevious);
int height = inlayHeight + editor.getLineHeight(); Rectangle visibleArea = scrollingModel.getVisibleArea();