private static void handleBeforeDocumentChange(@NotNull UndoManagerImpl undoManager, @NotNull Document document) {
    if (undoManager.isActive() && isUndoable(undoManager, document) && undoManager.isUndoOrRedoInProgress() &&
        document.getUserData(UNDOING_EDITOR_CHANGE) != Boolean.TRUE) {
      throw new IllegalStateException("Do not change documents during undo as it will break undo sequence.");
    }
  }
private static void handleBeforeDocumentChange(@NotNull UndoManagerImpl undoManager, @NotNull Document document)