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

Code before:
namespace winrt::TerminalApp::implementation
{
    struct TerminalTab;
}

enum class Borders : int
{
    None = 0x0,
    Top = 0x1,
    Bottom = 0x2,
    Left = 0x4,
    Right = 0x8
};
DEFINE_ENUM_FLAG_OPERATORS(Borders);

class Pane : public std::enable_shared_from_this<Pane>
{
public:
    Pane(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile,
         const winrt::Microsoft::Terminal::Control::TermControl& control,
         const bool lastFocused = false);

    std::shared_ptr<Pane> GetActivePane();
    winrt::Microsoft::Terminal::Control::TermControl GetTerminalControl();
    winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile();
    winrt::Microsoft::Terminal::Settings::Model::Profile GetProfile() const { return _profile; }

    winrt::Windows::UI::Xaml::Controls::Grid GetRootElement();

    bool WasLastFocused() const noexcept;
    void UpdateVisuals();
    void ClearActive();
    void SetActive();

    void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings,
                        const winrt::Microsoft::Terminal::Settings::Model::Profile& profile);
    void ResizeContent(const winrt::Windows::Foundation::Size& newSize);
    void Relayout();
    bool ResizePane(const winrt::Microsoft::Terminal::Settings::Model::ResizeDirection& direction);
    std::shared_ptr<Pane> NavigateDirection(const std::shared_ptr<Pane> sourcePane, const winrt::Microsoft::Terminal::Settings::Model::FocusDirection& direction);
    bool SwapPanes(std::shared_ptr<Pane> first, std::shared_ptr<Pane> second);

    std::shared_ptr<Pane> NextPane(const std::shared_ptr<Pane> pane);
    std::shared_ptr<Pane> PreviousPane(const std::shared_ptr<Pane> pane);

    std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> Split(winrt::Microsoft::Terminal::Settings::Model::SplitState splitType,
                                                                  const float splitSize,
                                                                  const winrt::Microsoft::Terminal::Settings::Model::Profile& profile,
                                                                  const winrt::Microsoft::Terminal::Control::TermControl& control);
    bool ToggleSplitOrientation();
    float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const;

Review comment (bug):
To be clear, `GetProfile()` would only return `nullptr` on non-leaf panes, right? Whereas `GetFocusedProfile()` performs a walk until it finds the focused pane, then gets that profile?

Code after:
namespace winrt::TerminalApp::implementation
{
    struct TerminalTab;
}

enum class Borders : int
{
    None = 0x0,
    Top = 0x1,
    Bottom = 0x2,
    Left = 0x4,
    Right = 0x8
};
DEFINE_ENUM_FLAG_OPERATORS(Borders);

class Pane : public std::enable_shared_from_this<Pane>
{
public:
    Pane(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile,
         const winrt::Microsoft::Terminal::Control::TermControl& control,
         const bool lastFocused = false);

    std::shared_ptr<Pane> GetActivePane();
    winrt::Microsoft::Terminal::Control::TermControl GetTerminalControl();
    winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile();

    // Method Description:
    // - If this is a leaf pane, return its profile.
    // - If this is a branch/root pane, return nullptr.
    winrt::Microsoft::Terminal::Settings::Model::Profile GetProfile() const
    {
        return _profile;
    }

    winrt::Windows::UI::Xaml::Controls::Grid GetRootElement();

    bool WasLastFocused() const noexcept;
    void UpdateVisuals();
    void ClearActive();
    void SetActive();

    void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings,
                        const winrt::Microsoft::Terminal::Settings::Model::Profile& profile);
    void ResizeContent(const winrt::Windows::Foundation::Size& newSize);
    void Relayout();
    bool ResizePane(const winrt::Microsoft::Terminal::Settings::Model::ResizeDirection& direction);
    std::shared_ptr<Pane> NavigateDirection(const std::shared_ptr<Pane> sourcePane, const winrt::Microsoft::Terminal::Settings::Model::FocusDirection& direction);
    bool SwapPanes(std::shared_ptr<Pane> first, std::shared_ptr<Pane> second);

    std::shared_ptr<Pane> NextPane(const std::shared_ptr<Pane> pane);
    std::shared_ptr<Pane> PreviousPane(const std::shared_ptr<Pane> pane);