String (@NotNull Editor editor, @NotNull List<? extends CaretInfo> carets) { CaretAndSelectionMarkup markup = new CaretAndSelectionMarkup(); // The expected state is properly sorted already, so it doesn't require extra sorting, // but for sake of consistency we use the same approach as for the actual caret state. for (CaretInfo expected : carets) { LogicalPosition position = expected.position; TextRange selection = expected.selection; if (selection != null) markup.addMark(selection.getStartOffset(), SELECTION_START_TAG); if (position != null) markup.addMark(editor.getDocument().getLineStartOffset(position.line) + position.column, CARET_TAG); if (selection != null) markup.addMark(selection.getEndOffset(), SELECTION_END_TAG); } return markup.insertMarks(editor.getDocument().getCharsSequence()); }