void (@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { CaretModel caretModel = editor.getCaretModel(); Document document = editor.getDocument(); int selectionStart = caret.getSelectionStart(); int startLine = document.getLineNumber(selectionStart); int selectionEnd = caret.getSelectionEnd(); int endLine = document.getLineNumber(selectionEnd); if (endLine > startLine && selectionEnd == document.getLineStartOffset(endLine)) endLine--; if (caretModel.getCaretCount() + endLine - startLine > caretModel.getMaxCaretCount()) { EditorUtil.notifyMaxCarets(editor); return; } caret.removeSelection(); boolean primary = caret.getOffset() != selectionStart; for (int i = startLine; i <= endLine; i++) { int targetOffset = document.getLineEndOffset(i); if (targetOffset == caret.getOffset()) { // move caret away, so that it doesn't prevent creating a new one // target offset doesn't matter, the caret is removed after the loop anyway caret.moveToOffset(targetOffset == 0 ? document.getTextLength() : 0); } caretModel.addCaret(editor.offsetToLogicalPosition(targetOffset), primary); } caretModel.removeCaret(caret); }