Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp (C++)

Code before:
        L"Tango Dark",
        L"Tango Light"
    };

    ColorSchemesPageViewModel::ColorSchemesPageViewModel(const Model::CascadiaSettings& settings) :
        _settings{ settings },
        _viewModelToSchemeMap{ winrt::single_threaded_map<Editor::ColorSchemeViewModel, Model::ColorScheme>() }
    {
        _MakeColorSchemeVMsHelper();
    }

    void ColorSchemesPageViewModel::UpdateSettings(const Model::CascadiaSettings& settings)
    {
        _settings = settings;

        // We want to re-initialize our AllColorSchemes list, but we want to make sure
        // we still have the same CurrentScheme as before (if that scheme still exists)

        // Store the name of the current scheme
        const auto currentSchemeName = HasCurrentScheme() ? CurrentScheme().Name() : hstring{};

        // Re-initialize the color scheme list
        _MakeColorSchemeVMsHelper();

        // Re-select the previously selected scheme if it exists
        if (currentSchemeName)
        {
            const auto it = _AllColorSchemes.First();
            while (it.HasCurrent())
            {
                auto scheme = *it;
                if (scheme.Name() == currentSchemeName)
                {
                    CurrentScheme(scheme);
                    break;
                }
                it.MoveNext();
            }
            if (!it.HasCurrent())
            {
                // we didn't find the previously selected scheme
                CurrentScheme(nullptr);
            }
        }
        else
        {
            // didn't have a scheme,
            // so skip over looking through the schemes
            CurrentScheme(nullptr);
        }
    }

Review comment (suggestion):
```suggestion
        if (!currentSchemeName.empty())
```

Code after:
        L"Tango Dark",
        L"Tango Light"
    };

    ColorSchemesPageViewModel::ColorSchemesPageViewModel(const Model::CascadiaSettings& settings) :
        _settings{ settings },
        _viewModelToSchemeMap{ winrt::single_threaded_map<Editor::ColorSchemeViewModel, Model::ColorScheme>() }
    {
        _MakeColorSchemeVMsHelper();
    }

    void ColorSchemesPageViewModel::UpdateSettings(const Model::CascadiaSettings& settings)
    {
        _settings = settings;

        // We want to re-initialize our AllColorSchemes list, but we want to make sure
        // we still have the same CurrentScheme as before (if that scheme still exists)

        // Store the name of the current scheme
        const auto currentSchemeName = HasCurrentScheme() ? CurrentScheme().Name() : hstring{};

        // Re-initialize the color scheme list
        _MakeColorSchemeVMsHelper();

        // Re-select the previously selected scheme if it exists
        if (!currentSchemeName.empty())
        {
            const auto it = _AllColorSchemes.First();
            while (it.HasCurrent())
            {
                auto scheme = *it;
                if (scheme.Name() == currentSchemeName)
                {
                    CurrentScheme(scheme);
                    break;
                }
                it.MoveNext();
            }
            if (!it.HasCurrent())
            {
                // we didn't find the previously selected scheme
                CurrentScheme(nullptr);
            }
        }
        else
        {
            // didn't have a scheme,
            // so skip over looking through the schemes
            CurrentScheme(nullptr);
        }
    }