void (@NotNull Editor editor, @NotNull Runnable runnable) { FileEditor fileEditor = TextEditorProvider.getInstance().getTextEditor(editor); Project project = editor.getProject(); assertNotNull(project); UndoManagerImpl undoManager = (UndoManagerImpl)UndoManager.getInstance(project); undoManager.setOverriddenEditorProvider(new CurrentEditorProvider() { @Override public @Nullable FileEditor getCurrentEditor(@Nullable Project project) { return fileEditor; } }); try { runnable.run(); } finally { undoManager.setOverriddenEditorProvider(null); } }