Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp (C++)

Code before:
//   generators. Set this to `false` for unit testing.
// Arguments:
// - addDynamicProfiles: if true, we'll add the built-in DPGs.
CascadiaSettings::CascadiaSettings(const bool addDynamicProfiles) :
    _globals{ winrt::make_self<implementation::GlobalAppSettings>() },
    _allProfiles{ winrt::single_threaded_observable_vector<Model::Profile>() },
    _activeProfiles{ winrt::single_threaded_observable_vector<Model::Profile>() },
    _warnings{ winrt::single_threaded_vector<SettingsLoadWarnings>() },
    _deserializationErrorMessage{ L"" },
    _defaultTerminals{ winrt::single_threaded_observable_vector<Model::DefaultTerminal>() },
    _currentDefaultTerminal{ nullptr }
{
    if (addDynamicProfiles)
    {
        _profileGenerators.emplace_back(std::make_unique<PowershellCoreProfileGenerator>());
        _profileGenerators.emplace_back(std::make_unique<WslDistroGenerator>());
        _profileGenerators.emplace_back(std::make_unique<AzureCloudShellGenerator>());
    }
}

CascadiaSettings::CascadiaSettings(winrt::hstring json) :
    CascadiaSettings(false)
{
    const auto jsonString{ til::u16u8(json) };
    _ParseJsonString(jsonString, false);
    LayerJson(_userSettings);
    _ValidateSettings();
}

winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings CascadiaSettings::Copy() const
{
    // dynamic profile generators added by default
    auto settings{ winrt::make_self<CascadiaSettings>() };
    settings->_globals = _globals->Copy();
    for (auto warning : _warnings)
    {
        settings->_warnings.Append(warning);
    }
    settings->_loadError = _loadError;
    settings->_deserializationErrorMessage = _deserializationErrorMessage;
    settings->_userSettingsString = _userSettingsString;
    settings->_userSettings = _userSettings;
    settings->_defaultSettings = _defaultSettings;

    settings->_defaultTerminals = _defaultTerminals;
    settings->_currentDefaultTerminal = _currentDefaultTerminal;

    _CopyProfileInheritanceTree(settings);

    return *settings;
}

Review comment (suggestion):
this method is only used in the tests; adding this ensures that `ProfileDefaults()` is populated :|

we gotta fix this yo

Code after:
//   generators. Set this to `false` for unit testing.
// Arguments:
// - addDynamicProfiles: if true, we'll add the built-in DPGs.
CascadiaSettings::CascadiaSettings(const bool addDynamicProfiles) :
    _globals{ winrt::make_self<implementation::GlobalAppSettings>() },
    _allProfiles{ winrt::single_threaded_observable_vector<Model::Profile>() },
    _activeProfiles{ winrt::single_threaded_observable_vector<Model::Profile>() },
    _warnings{ winrt::single_threaded_vector<SettingsLoadWarnings>() },
    _deserializationErrorMessage{ L"" },
    _defaultTerminals{ winrt::single_threaded_observable_vector<Model::DefaultTerminal>() },
    _currentDefaultTerminal{ nullptr }
{
    if (addDynamicProfiles)
    {
        _profileGenerators.emplace_back(std::make_unique<PowershellCoreProfileGenerator>());
        _profileGenerators.emplace_back(std::make_unique<WslDistroGenerator>());
        _profileGenerators.emplace_back(std::make_unique<AzureCloudShellGenerator>());
    }
}

CascadiaSettings::CascadiaSettings(winrt::hstring json) :
    CascadiaSettings(false)
{
    const auto jsonString{ til::u16u8(json) };
    _ParseJsonString(jsonString, false);
    _ApplyDefaultsFromUserSettings();
    LayerJson(_userSettings);
    _ValidateSettings();
}

winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings CascadiaSettings::Copy() const
{
    // dynamic profile generators added by default
    auto settings{ winrt::make_self<CascadiaSettings>() };
    settings->_globals = _globals->Copy();
    for (auto warning : _warnings)
    {
        settings->_warnings.Append(warning);
    }
    settings->_loadError = _loadError;
    settings->_deserializationErrorMessage = _deserializationErrorMessage;
    settings->_userSettingsString = _userSettingsString;
    settings->_userSettings = _userSettings;
    settings->_defaultSettings = _defaultSettings;

    settings->_defaultTerminals = _defaultTerminals;
    settings->_currentDefaultTerminal = _currentDefaultTerminal;

    _CopyProfileInheritanceTree(settings);

    return *settings;