void (final Project project, Editor editor, final TextRange textRange) { final FoldRegion[] foldRegions = CodeFoldingManager.getInstance(project).getFoldRegionsAtOffset(editor, textRange.getStartOffset()); boolean anyCollapsed = false; for (final FoldRegion foldRegion : foldRegions) { if (!foldRegion.isExpanded()) { anyCollapsed = true; break; } } if (anyCollapsed) { editor.getFoldingModel().runBatchFoldingOperation(() -> { for (final FoldRegion foldRegion : foldRegions) { if (!foldRegion.isExpanded()) { foldRegion.setExpanded(true); } } }); } }