void (EditorEx editor, Random random) { DocumentEx document = editor.getDocument(); int textLength = document.getTextLength(); if (textLength <= 1) return; int count = 1 + random.nextInt(textLength - 1); int srcStart = random.nextInt(textLength - count + 1); int targetPos = random.nextInt(textLength - count); int targetOffset = targetPos < srcStart ? targetPos : targetPos + count + 1; WriteCommandAction.writeCommandAction(getProject()).run(() -> document.moveText(srcStart, srcStart + count, targetOffset)); }