Repository: microsoft/terminal
File: src/cascadia/TerminalApp/Pane.cpp (C++)

Code before:
int Pane::GetLeafPaneCount() const noexcept
{
    return _IsLeaf() ? 1 : (_firstChild->GetLeafPaneCount() + _secondChild->GetLeafPaneCount());
}

// Method Description:
// - Should be called when this pane is created via a default terminal handoff
// - Finalizes our configuration given the information that we have been
//   created via default handoff
void Pane::FinalizeConfigurationGivenDefault()
{
    if (_IsLeaf())
    {
        if (_profile)
        {
            if (_profile.CloseOnExit() == CloseOnExitMode::GracefulIfLaunchedByTerminal)
            {
                // We only want to close 'gracefully' if we were launched by Terminal
                // Since we were launched via defterm, override this (i.e. it will
                // be treated as 'always', see _ControlConnectionStateChangedHandler
                // for where this boolean is used, and see GH #13325 for discussion)
                _overrideCloseOnExit = true;
            }
        }
    }
}

// Method Description:
// - Returns true if the pane or one of its descendants is read-only
bool Pane::ContainsReadOnly() const
{
    return _IsLeaf() ? _control.ReadOnly() : (_firstChild->ContainsReadOnly() || _secondChild->ContainsReadOnly());
}

// Method Description:
// - If we're a parent, place the taskbar state for all our leaves into the
//   provided vector.
// - If we're a leaf, place our own state into the vector.
// Arguments:
// - states: a vector that will receive all the states of all leaves in the tree
// Return Value:
// - <none>
void Pane::CollectTaskbarStates(std::vector<winrt::TerminalApp::TaskbarState>& states)
{
    if (_IsLeaf())
    {
        auto tbState{ winrt::make<winrt::TerminalApp::implementation::TaskbarState>(_control.TaskbarState(),
                                                                                    _control.TaskbarProgress()) };
        states.push_back(tbState);
    }
    else

Review comment (suggestion):
```suggestion
    if (_IsLeaf() && _profile && _profile.CloseOnExit() == CloseOnExitMode::GracefulIfLaunchedByTerminal)
    {
        // We only want to close 'gracefully' if we were launched by Terminal
        // Since we were launched via defterm, override this (i.e. it will
        // be treated as 'always', see _ControlConnectionStateChangedHandler
        // for where this boolean is used, and see GH #13325 for discussion)
        _overrideCloseOnExit = true;
    }
```

or at least you can combine the `_profile` and close on exit check to remove a level of nesting

Code after:

int Pane::GetLeafPaneCount() const noexcept
{
    return _IsLeaf() ? 1 : (_firstChild->GetLeafPaneCount() + _secondChild->GetLeafPaneCount());
}

// Method Description:
// - Should be called when this pane is created via a default terminal handoff
// - Finalizes our configuration given the information that we have been
//   created via default handoff
void Pane::FinalizeConfigurationGivenDefault()
{
    _isDefTermSession = true;
}

// Method Description:
// - Returns true if the pane or one of its descendants is read-only
bool Pane::ContainsReadOnly() const
{
    return _IsLeaf() ? _control.ReadOnly() : (_firstChild->ContainsReadOnly() || _secondChild->ContainsReadOnly());
}

// Method Description:
// - If we're a parent, place the taskbar state for all our leaves into the
//   provided vector.
// - If we're a leaf, place our own state into the vector.
// Arguments:
// - states: a vector that will receive all the states of all leaves in the tree
// Return Value:
// - <none>
void Pane::CollectTaskbarStates(std::vector<winrt::TerminalApp::TaskbarState>& states)
{
    if (_IsLeaf())
    {
        auto tbState{ winrt::make<winrt::TerminalApp::implementation::TaskbarState>(_control.TaskbarState(),
                                                                                    _control.TaskbarProgress()) };
        states.push_back(tbState);
    }
    else
    {
        _firstChild->CollectTaskbarStates(states);
        _secondChild->CollectTaskbarStates(states);
    }
}