void (@NotNull Runnable runnable) { Runnable lastRunnable = runnable; for (EditorEx editor : myEditors) { final Runnable finalRunnable = lastRunnable; lastRunnable = () -> { if (DiffUtil.isFocusedComponent(editor.getComponent())) { editor.getFoldingModel().runBatchFoldingOperationDoNotCollapseCaret(finalRunnable); } else { editor.getFoldingModel().runBatchFoldingOperation(finalRunnable); } }; } myDuringSynchronize = true; try { lastRunnable.run(); } finally { myDuringSynchronize = false; } }