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

Code before:
    }

    double LaunchViewModel::InitialPosY()
    {
        const auto y = _Settings.GlobalSettings().InitialPosition().Y;
        // If there's no value here, return NAN - XAML will ignore it and
        // put the placeholder text in the box instead
        if (auto yCoord{ y.try_as<int64_t>() })
        {
            return yCoord.has_value() ? gsl::narrow_cast<double>(yCoord.value()) : NAN;
        }
        return NAN;
    }

    void LaunchViewModel::InitialPosX(double xCoord)
    {
        LaunchPosition newPos;
        // If the value was cleared, xCoord will be NAN, so check for that
        if (xCoord)
        {
            newPos = LaunchPosition{ gsl::narrow_cast<int64_t>(xCoord), _Settings.GlobalSettings().InitialPosition().Y };
        }
        else
        {
            newPos = LaunchPosition{ nullptr, _Settings.GlobalSettings().InitialPosition().Y };
        }
        _Settings.GlobalSettings().InitialPosition(newPos);
    }

    void LaunchViewModel::InitialPosY(double yCoord)
    {
        LaunchPosition newPos;
        // If the value was cleared, yCoord will be NAN, so check for that
        if (yCoord)
        {
            newPos = LaunchPosition{ _Settings.GlobalSettings().InitialPosition().X, gsl::narrow_cast<int64_t>(yCoord) };
        }
        else
        {
            newPos = LaunchPosition{ _Settings.GlobalSettings().InitialPosition().X, nullptr };
        }
        _Settings.GlobalSettings().InitialPosition(newPos);
    }

    winrt::Windows::Foundation::IInspectable LaunchViewModel::CurrentDefaultProfile()
    {
        const auto defaultProfileGuid{ _Settings.GlobalSettings().DefaultProfile() };
        return winrt::box_value(_Settings.FindProfile(defaultProfileGuid));
    }

    void LaunchViewModel::CurrentDefaultProfile(const IInspectable& value)

Review comment (refactor):
This checks if xCoord is not 0 and not if it's non-NaN. Additionally (but this is more of a stylistic criticism), I'd deduplicate the two branches.

```suggestion
        winrt::Windows::Foundation::IReference<int64_t> xCoordRef;
        if (!isnan(xCoord) {
            xCoordRef = gsl::narrow_cast<int64_t>(xCoord);
        }

        LaunchPosition newPos{ xCoordRef, _Settings.GlobalSettings().InitialPosition().Y };
```

Code after:
    winrt::hstring LaunchViewModel::LaunchParametersCurrentValue()
    {
        const auto launchModeString = CurrentLaunchMode().as<EnumEntry>()->EnumName();
        const auto centerOnLaunchString = CenterOnLaunch() ? RS_(L"Globals_CenterOnLaunchOn") : RS_(L"Globals_CenterOnLaunchOff");

        winrt::hstring result;

        if (UseDefaultLaunchPosition())
        {
            result = fmt::format(L"{}, {}, {}", launchModeString, RS_(L"Globals_LaunchModeDefault/Content"), centerOnLaunchString);
        }
        else
        {
            const std::wstring xPosString = isnan(InitialPosX()) ? RS_(L"Globals_LaunchModeDefault/Content").c_str() : std::to_wstring(gsl::narrow_cast<int>(InitialPosX()));
            const std::wstring yPosString = isnan(InitialPosY()) ? RS_(L"Globals_LaunchModeDefault/Content").c_str() : std::to_wstring(gsl::narrow_cast<int>(InitialPosY()));
            result = fmt::format(L"{}, ({},{}), {}", launchModeString, xPosString, yPosString, centerOnLaunchString);
        }
        return result;
    }

    double LaunchViewModel::InitialPosX()
    {
        const auto x = _Settings.GlobalSettings().InitialPosition().X;
        // If there's no value here, return NAN - XAML will ignore it and
        // put the placeholder text in the box instead
        const auto xCoord = x.try_as<int64_t>();
        return xCoord.has_value() ? gsl::narrow_cast<double>(xCoord.value()) : NAN;
    }

    double LaunchViewModel::InitialPosY()
    {
        const auto y = _Settings.GlobalSettings().InitialPosition().Y;
        // If there's no value here, return NAN - XAML will ignore it and
        // put the placeholder text in the box instead
        const auto yCoord = y.try_as<int64_t>();
        return yCoord.has_value() ? gsl::narrow_cast<double>(yCoord.value()) : NAN;
    }

    void LaunchViewModel::InitialPosX(double xCoord)
    {
        winrt::Windows::Foundation::IReference<int64_t> xCoordRef;
        // If the value was cleared, xCoord will be NAN, so check for that
        if (!isnan(xCoord))
        {
            xCoordRef = gsl::narrow_cast<int64_t>(xCoord);
        }
        const LaunchPosition newPos{ xCoordRef, _Settings.GlobalSettings().InitialPosition().Y };
        _Settings.GlobalSettings().InitialPosition(newPos);
        _NotifyChanges(L"LaunchParametersCurrentValue");
    }