void (final EditorEx editor, Random random) { DocumentEx document = editor.getDocument(); if (document.isInBulkUpdate()) return; int textLength = document.getTextLength(); if (textLength <= 0) return; final int startOffset = random.nextInt(textLength + 1); final int endOffset = random.nextInt(textLength + 1); if (startOffset == endOffset) return; final FoldingModel foldingModel = editor.getFoldingModel(); foldingModel.runBatchFoldingOperation(() -> foldingModel.addFoldRegion(Math.min(startOffset, endOffset), Math.max(startOffset, endOffset), random.nextBoolean() ? "." : "")); }