void (@NotNull ClientState state, UndoConfirmationPolicy undoConfirmationPolicy, boolean recordOriginalReference) { if (state.myCommandLevel == 0) { state.myCurrentMerger = new CommandMerger(state, CommandProcessor.getInstance().isUndoTransparentActionInProgress()); if (recordOriginalReference && myProject != null) { Editor editor = null; final Application application = ApplicationManager.getApplication(); if (application.isUnitTestMode() || application.isHeadlessEnvironment()) { editor = CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext()); } else { FileEditor fileEditor = getEditorProvider().getCurrentEditor(myProject); if (fileEditor instanceof TextEditor) { editor = ((TextEditor)fileEditor).getEditor(); } } if (editor != null) { Document document = editor.getDocument(); VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (file != null && file.isValid()) { state.myOriginatorReference = DocumentReferenceManager.getInstance().create(file); } } } } LOG.assertTrue(state.myCurrentMerger != null, String.valueOf(state.myCommandLevel)); state.myCurrentMerger.setBeforeState(getCurrentState()); state.myCurrentMerger.mergeUndoConfirmationPolicy(undoConfirmationPolicy); state.myCommandLevel++; }