FoldRegion (@NotNull Editor editor, final int startOffset, final int endOffset, final String placeholder, final boolean collapse) { final FoldingModel foldingModel = editor.getFoldingModel(); final Ref<FoldRegion> ref = new Ref<>(); foldingModel.runBatchFoldingOperation(() -> { FoldRegion region = foldingModel.addFoldRegion(startOffset, endOffset, placeholder); assertNotNull(region); region.setExpanded(!collapse); ref.set(region); }); return ref.get(); }