void (@NotNull Caret caret, boolean resetToSingleLineAtCaret) { Editor editor = caret.getEditor(); int lineNumber = caret.getLogicalPosition().line; Document document = editor.getDocument(); if (lineNumber >= document.getLineCount()) { return; } TextRange range = EditorUtil.calcSurroundingTextRange(editor, resetToSingleLineAtCaret ? caret.getVisualPosition() : caret.getSelectionStartPosition(), resetToSingleLineAtCaret ? caret.getVisualPosition() : caret.getSelectionEndPosition()); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); caret.setSelection(range.getStartOffset(), range.getEndOffset()); }