void (Editor editor, Random random) { Document document = editor.getDocument(); int offset = random.nextInt(document.getTextLength() + 1); CharSequence text = generateText(random); WriteCommandAction.runWriteCommandAction(getProject(), () -> document.insertString(offset, text)); }