void (@NotNull AnActionEvent e, boolean state) { if (state) { EditorUtil.scrollToTheEnd(myEditor); } else { int lastLine = Math.max(0, myEditor.getDocument().getLineCount() - 1); LogicalPosition currentPosition = myEditor.getCaretModel().getLogicalPosition(); LogicalPosition position = new LogicalPosition(Math.max(0, Math.min(currentPosition.line, lastLine - 1)), currentPosition.column); myEditor.getCaretModel().moveToLogicalPosition(position); } }