void (final EditorEx editor, Random random) { DocumentEx document = editor.getDocument(); if (document.isInBulkUpdate()) return; int lineCount = Math.max(1, document.getLineCount()); final int startLine = random.nextInt(lineCount); final int endLine = random.nextInt(lineCount); final FoldingModel foldingModel = editor.getFoldingModel(); foldingModel.runBatchFoldingOperation(() -> foldingModel.addCustomLinesFolding(Math.min(startLine, endLine), Math.max(startLine, endLine), MyCustomFoldRegionRenderer.INSTANCE)); }