void () { int textLength = myDocument.getTextLength(); if (textLength <= 0) return; int startOffset = myRandom.nextInt(textLength); int endOffset = Math.min(textLength, startOffset + 1 + myRandom.nextInt(MAX_CHARS_PER_OPERATION)); int targetOffset = myRandom.nextInt(textLength + 1); if (targetOffset < startOffset || targetOffset > endOffset) { runWriteCommand(() -> myDocument.moveText(startOffset, endOffset, targetOffset)); } }