void (Editor editor, CaretAndSelectionState caretsState) { CaretModel caretModel = editor.getCaretModel(); List<CaretState> states = new ArrayList<>(caretsState.carets.size()); for (CaretInfo caret : caretsState.carets) { states.add(new CaretState(caret.position == null ? null : editor.offsetToLogicalPosition(caret.getCaretOffset(editor.getDocument())), caret.selection == null ? null : editor.offsetToLogicalPosition(caret.selection.getStartOffset()), caret.selection == null ? null : editor.offsetToLogicalPosition(caret.selection.getEndOffset()))); } caretModel.setCaretsAndSelections(states); if (caretsState.blockSelection != null) { editor.getSelectionModel().setBlockSelection(editor.offsetToLogicalPosition(caretsState.blockSelection.getStartOffset()), editor.offsetToLogicalPosition(caretsState.blockSelection.getEndOffset())); } }