void (@NotNull Editor editor, boolean isWithSelection) { SelectionModel selectionModel = editor.getSelectionModel(); int selectionStart = selectionModel.getLeadSelectionOffset(); CaretModel caretModel = editor.getCaretModel(); LogicalPosition blockSelectionStart = caretModel.getLogicalPosition(); Rectangle visibleArea = getVisibleArea(editor); int maxY = visibleArea.y + visibleArea.height - editor.getLineHeight(); int lineNumber = editor.yToVisualLine(maxY); if (lineNumber > 0 && maxY < editor.visualLineToY(lineNumber) && visibleArea.y <= editor.visualLineToY(lineNumber - 1)) { lineNumber--; } VisualPosition pos = new VisualPosition(lineNumber, editor.getCaretModel().getVisualPosition().column); editor.getCaretModel().moveToVisualPosition(pos); setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart); }