void (FileEditor currentEditor, Runnable task) { UndoManagerImpl undoManager = getUndoManager(); try { undoManager.setOverriddenEditorProvider(new CurrentEditorProvider() { @Override public @Nullable FileEditor getCurrentEditor(@Nullable Project project) { return currentEditor; } }); task.run(); } finally { undoManager.setOverriddenEditorProvider(null); } }