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

Code before:
    if (source.HasSelectionBackground() || source.SelectionBackgroundOverrideSource() != nullptr)
    {
        duplicated->SelectionBackground(source.SelectionBackground());
    }
    if (source.HasCursorColor() || source.CursorColorOverrideSource() != nullptr)
    {
        duplicated->CursorColor(source.CursorColor());
    }
    if (source.HasHistorySize() || source.HistorySizeOverrideSource() != nullptr)
    {
        duplicated->HistorySize(source.HistorySize());
    }
    if (source.HasSnapOnInput() || source.SnapOnInputOverrideSource() != nullptr)
    {
        duplicated->SnapOnInput(source.SnapOnInput());
    }
    if (source.HasAltGrAliasing() || source.AltGrAliasingOverrideSource() != nullptr)
    {
        duplicated->AltGrAliasing(source.AltGrAliasing());
    }
    if (source.HasCursorShape() || source.CursorShapeOverrideSource() != nullptr)
    {
        duplicated->CursorShape(source.CursorShape());
    }
    if (source.HasCursorHeight() || source.CursorHeightOverrideSource() != nullptr)
    {
        duplicated->CursorHeight(source.CursorHeight());
    }
    if (source.HasBellStyle() || source.BellStyleOverrideSource() != nullptr)
    {
        duplicated->BellStyle(source.BellStyle());
    }
    if (source.HasPixelShaderPath() || source.PixelShaderPathOverrideSource() != nullptr)
    {
        duplicated->PixelShaderPath(source.PixelShaderPath());
    }
    if (source.HasBackgroundImageAlignment() || source.BackgroundImageAlignmentOverrideSource() != nullptr)
    {
        duplicated->BackgroundImageAlignment(source.BackgroundImageAlignment());
    }
    if (source.HasConnectionType())
    {
        duplicated->ConnectionType(source.ConnectionType());
    }

    return *duplicated;
}

// Method Description:
// - Gets our list of warnings we found during loading. These are things that we
//   knew were bad when we called `_ValidateSettings` last.

Review comment (refactor):
Just so we're clear: when you duplicate Command Prompt, what do you get? When you duplicate WSL, what do you get? When you have a `defaults` layer, and then duplicate a leaf profile, what do you get?

I think that Command Prompt will give you a full JSON block. I think that WSL will give you a partial JSON block. I think that having a `defaults` layer will _copy all of the defaults into the new json block_.

Code after:
        // We need this to be able to call CopyAppearance (it is alright to simply call CopyAppearance here
        // instead of needing a separate function like DuplicateAppearance since UnfocusedAppearance is treated
        // as a single setting)
        winrt::com_ptr<AppearanceConfig> sourceUnfocusedAppearanceImpl;
        sourceUnfocusedAppearanceImpl.copy_from(winrt::get_self<AppearanceConfig>(source.UnfocusedAppearance()));

        // Get a weak ref to the duplicate profile so we can provide a source profile to the new UnfocusedAppearance
        // we are about to create
        const auto weakRefToDuplicated = weak_ref<Model::Profile>(*duplicated);
        auto duplicatedUnfocusedAppearanceImpl = AppearanceConfig::CopyAppearance(sourceUnfocusedAppearanceImpl, weakRefToDuplicated);

        // Make sure to add the default appearance of the duplicated profile as a parent to the duplicate's UnfocusedAppearance
        winrt::com_ptr<AppearanceConfig> duplicatedDefaultAppearanceImpl;
        duplicatedDefaultAppearanceImpl.copy_from(winrt::get_self<AppearanceConfig>(duplicated->DefaultAppearance()));
        duplicatedUnfocusedAppearanceImpl->InsertParent(duplicatedDefaultAppearanceImpl);

        // Finally, set the duplicate's UnfocusedAppearance
        duplicated->UnfocusedAppearance(*duplicatedUnfocusedAppearanceImpl);
    }

    if (source.HasConnectionType())
    {
        duplicated->ConnectionType(source.ConnectionType());
    }

    return *duplicated;
}

// Method Description:
// - Gets our list of warnings we found during loading. These are things that we
//   knew were bad when we called `_ValidateSettings` last.
// Return Value:
// - a reference to our list of warnings.
IVectorView<winrt::Microsoft::Terminal::Settings::Model::SettingsLoadWarnings> CascadiaSettings::Warnings()
{
    return _warnings.GetView();
}

void CascadiaSettings::ClearWarnings()
{
    _warnings.Clear();
}

void CascadiaSettings::AppendWarning(SettingsLoadWarnings warning)
{
    _warnings.Append(warning);
}

winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Settings::Model::SettingsLoadErrors> CascadiaSettings::GetLoadingError()
{
    return _loadError;