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

Code before:
                                (_tabs.Size() > 1) ||
                                _settings.GlobalSettings().AlwaysShowTabs());

        // collapse/show the tabs themselves
        _tabView.Visibility(isVisible ? Visibility::Visible : Visibility::Collapsed);

        // collapse/show the row that the tabs are in.
        // NaN is the special value XAML uses for "Auto" sizing.
        _tabRow.Height(isVisible ? NAN : 0);
    }

    // Method Description:
    // - Duplicates the current focused tab
    void TerminalPage::_DuplicateTabViewItem()
    {
        if (const auto terminalTab{ _GetFocusedTabImpl() })
        {
            _DuplicateTab(*terminalTab);
        }
    }

    // Method Description:
    // - Duplicates specified tab
    // Arguments:
    // - tab: tab to duplicate
    void TerminalPage::_DuplicateTab(const TerminalTab& tab)
    {
        try
        {
            // TODO: GH#5047 - In the future, we should get the Profile of
            // the focused pane, and use that to build a new instance of the
            // settings so we can duplicate this tab/pane.
            //
            // Currently, if the profile doesn't exist anymore in our
            // settings, we'll silently do nothing.
            //
            // In the future, it will be preferable to just duplicate the
            // current control's settings, but we can't do that currently,
            // because we won't be able to create a new instance of the
            // connection without keeping an instance of the original Profile
            // object around.

            const auto& profileGuid = tab.GetFocusedProfile();
            if (profileGuid.has_value())
            {
                const auto settings{ winrt::make<TerminalSettings>(_settings, profileGuid.value(), *_bindings) };
                const auto workingDirectory = tab.GetActiveTerminalControl().WorkingDirectory();
                const auto validWorkingDirectory = !workingDirectory.empty();
                if (validWorkingDirectory)
                {
                    settings.StartingDirectory(workingDirectory);

Review comment (refactor):
This is a nit, but mind renaming the function above to something like "_DuplicateCurrentTab"? I feel like somebody will get confused between `_DuplicateTab(tab)` and `_DuplicateTabViewItem()` at some point.

Code after:
                                (_tabs.Size() > 1) ||
                                _settings.GlobalSettings().AlwaysShowTabs());

        // collapse/show the tabs themselves
        _tabView.Visibility(isVisible ? Visibility::Visible : Visibility::Collapsed);

        // collapse/show the row that the tabs are in.
        // NaN is the special value XAML uses for "Auto" sizing.
        _tabRow.Height(isVisible ? NAN : 0);
    }

    // Method Description:
    // - Duplicates the current focused tab
    void TerminalPage::_DuplicateFocusedTab()
    {
        if (const auto terminalTab{ _GetFocusedTabImpl() })
        {
            _DuplicateTab(*terminalTab);
        }
    }

    // Method Description:
    // - Duplicates specified tab
    // Arguments:
    // - tab: tab to duplicate
    void TerminalPage::_DuplicateTab(const TerminalTab& tab)
    {
        try
        {
            // TODO: GH#5047 - In the future, we should get the Profile of
            // the focused pane, and use that to build a new instance of the
            // settings so we can duplicate this tab/pane.
            //
            // Currently, if the profile doesn't exist anymore in our
            // settings, we'll silently do nothing.
            //
            // In the future, it will be preferable to just duplicate the
            // current control's settings, but we can't do that currently,
            // because we won't be able to create a new instance of the
            // connection without keeping an instance of the original Profile
            // object around.

            const auto& profileGuid = tab.GetFocusedProfile();
            if (profileGuid.has_value())
            {
                const auto settings{ winrt::make<TerminalSettings>(_settings, profileGuid.value(), *_bindings) };
                const auto workingDirectory = tab.GetActiveTerminalControl().WorkingDirectory();
                const auto validWorkingDirectory = !workingDirectory.empty();
                if (validWorkingDirectory)
                {
                    settings.StartingDirectory(workingDirectory);