void (Editor editor, Random random) { Document document = editor.getDocument(); int textLength = document.getTextLength(); if (textLength <= 0) return; int[] offsets = {random.nextInt(textLength + 1), random.nextInt(textLength + 1), random.nextInt(textLength + 1)}; Arrays.sort(offsets); if (offsets[0] == offsets[1] || offsets[1] == offsets[2]) return; WriteCommandAction.runWriteCommandAction(getProject(), () -> { if (random.nextBoolean()) { ((DocumentEx)document).moveText(offsets[0], offsets[1], offsets[2]); } else { ((DocumentEx)document).moveText(offsets[1], offsets[2], offsets[0]); } }); }