void (@NotNull Editor editor, @NotNull Runnable operation) { if (editor.getDocument().isInBulkUpdate()) { Disposable disposable = Disposer.newDisposable(); disposeWithEditor(editor, disposable); editor.getDocument().addDocumentListener(new DocumentListener() { @Override public void bulkUpdateFinished(@NotNull Document document) { editor.getFoldingModel().runBatchFoldingOperation(operation); Disposer.dispose(disposable); } }); } else { editor.getFoldingModel().runBatchFoldingOperation(operation); } }