void (@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { if (editor.getSelectionModel().hasSelection()) { int selStart = editor.getSelectionModel().getSelectionStart(); int selEnd = editor.getSelectionModel().getSelectionEnd(); if (selEnd > selStart && DocumentUtil.isAtLineStart(selEnd, editor.getDocument())) { selEnd--; } VisualPosition rangeStart = editor.offsetToVisualPosition(Math.min(selStart, selEnd)); VisualPosition rangeEnd = editor.offsetToVisualPosition(Math.max(selStart, selEnd)); TextRange copiedRange = DuplicateAction.duplicateLinesRange(editor, rangeStart, rangeEnd); editor.getSelectionModel().setSelection(copiedRange.getStartOffset(), copiedRange.getEndOffset()); } else { VisualPosition caretPos = editor.getCaretModel().getVisualPosition(); DuplicateAction.duplicateLinesRange(editor, caretPos, caretPos); } }