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

Code before:
    {
        // if there is actually a previous pane
        if (mruPanes.size() > 1)
        {
            return FindPane(mruPanes.at(1));
        }
        return nullptr;
    }

    // Check if we in-order traversal is requested
    if (direction == FocusDirection::NextInOrder)
    {
        return NextPane(sourcePane);
    }

    if (direction == FocusDirection::PreviousInOrder)
    {
        return PreviousPane(sourcePane);
    }

    // We are left with directional traversal now
    // If the focus direction does not match the split direction, the source pane
    // and its neighbor must necessarily be contained within the same child.
    if (!DirectionMatchesSplit(direction, _splitState))
    {
        if (auto p = _firstChild->NavigateDirection(sourcePane, direction, mruPanes))
        {
            return p;
        }
        return _secondChild->NavigateDirection(sourcePane, direction, mruPanes);
    }

    // Since the direction is the same as our split, it is possible that we must
    // move focus from from one child to another child.
    // We now must keep track of state while we recurse.
    // If we have it, get the size of this pane.
    const auto scaleX = _root.ActualWidth() > 0 ? gsl::narrow_cast<float>(_root.ActualWidth()) : 1.f;
    const auto scaleY = _root.ActualHeight() > 0 ? gsl::narrow_cast<float>(_root.ActualHeight()) : 1.f;
    const auto paneNeighborPair = _FindPaneAndNeighbor(sourcePane, direction, { 0, 0, scaleX, scaleY });

    if (paneNeighborPair.source && paneNeighborPair.neighbor)
    {
        return paneNeighborPair.neighbor;
    }

    return nullptr;
}

// Method Description:
// - Attempts to find the succeeding pane of the provided pane.
// - NB: If targetPane is not a leaf, then this will return one of its children.

Review comment (suggestion):
```suggestion
        if (const auto p = _firstChild->NavigateDirection(sourcePane, direction, mruPanes))
```
while you're here 😉

Code after:
    {
        // If there is actually a previous pane.
        if (mruPanes.size() > 1)
        {
            // This could return nullptr if the id is not actually in the tree.
            return FindPane(mruPanes.at(1));
        }
        return nullptr;
    }

    // Check if we in-order traversal is requested
    if (direction == FocusDirection::NextInOrder)
    {
        return NextPane(sourcePane);
    }

    if (direction == FocusDirection::PreviousInOrder)
    {
        return PreviousPane(sourcePane);
    }

    // We are left with directional traversal now
    // If the focus direction does not match the split direction, the source pane
    // and its neighbor must necessarily be contained within the same child.
    if (!DirectionMatchesSplit(direction, _splitState))
    {
        if (const auto p = _firstChild->NavigateDirection(sourcePane, direction, mruPanes))
        {
            return p;
        }
        return _secondChild->NavigateDirection(sourcePane, direction, mruPanes);
    }

    // Since the direction is the same as our split, it is possible that we must
    // move focus from from one child to another child.
    // We now must keep track of state while we recurse.
    // If we have it, get the size of this pane.
    const auto scaleX = _root.ActualWidth() > 0 ? gsl::narrow_cast<float>(_root.ActualWidth()) : 1.f;
    const auto scaleY = _root.ActualHeight() > 0 ? gsl::narrow_cast<float>(_root.ActualHeight()) : 1.f;
    const auto paneNeighborPair = _FindPaneAndNeighbor(sourcePane, direction, { 0, 0, scaleX, scaleY });

    if (paneNeighborPair.source && paneNeighborPair.neighbor)
    {
        return paneNeighborPair.neighbor;
    }

    return nullptr;
}

// Method Description:
// - Attempts to find the succeeding pane of the provided pane.