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

Code before:
    {
        if (auto index{ _GetFocusedTabIndex() })
        {
            if (auto terminalTab = _GetTerminalTabImpl(_tabs.GetAt(*index)))
            {
                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 = terminalTab->GetFocusedProfile();
                    if (profileGuid.has_value())
                    {
                        const auto settings{ winrt::make<TerminalSettings>(_settings, profileGuid.value(), *_bindings) };
                        const auto workingDirectory = terminalTab->GetActiveTerminalControl().WorkingDirectory();
                        const auto validWorkingDirectory = !workingDirectory.empty();
                        if (validWorkingDirectory)
                        {
                            settings.StartingDirectory(workingDirectory);
                        }

                        _CreateNewTabFromSettings(profileGuid.value(), settings);
                    }
                }
                CATCH_LOG();
            }
        }
    }

    // Method Description:
    // - Look for the index of the input tabView in the tabs vector,
    //   and call _RemoveTabViewItemByIndex
    // Arguments:
    // - tabViewItem: the TabViewItem in the TabView that is being removed.
    void TerminalPage::_RemoveTabViewItem(const MUX::Controls::TabViewItem& tabViewItem)
    {
        uint32_t tabIndexFromControl = 0;
        if (_tabView.TabItems().IndexOf(tabViewItem, tabIndexFromControl))
        {
            // If IndexOf returns true, we've actually got an index
            _RemoveTabViewItemByIndex(tabIndexFromControl);

Review comment (suggestion):
I relaxed the validation per the comments by @zadjii-msft in https://github.com/microsoft/terminal/issues/8166#issuecomment-724678264

I'm not sure how we handle `wt -d c:\some\invalid\path` nowadays. Could use some help here.

Code after:
        _actionDispatch->ScrollUpPage({ this, &TerminalPage::_HandleScrollUpPage });
        _actionDispatch->ScrollDownPage({ this, &TerminalPage::_HandleScrollDownPage });
        _actionDispatch->ScrollToTop({ this, &TerminalPage::_HandleScrollToTop });
        _actionDispatch->ScrollToBottom({ this, &TerminalPage::_HandleScrollToBottom });
        _actionDispatch->OpenSettings({ this, &TerminalPage::_HandleOpenSettings });
        _actionDispatch->PasteText({ this, &TerminalPage::_HandlePasteText });
        _actionDispatch->NewTab({ this, &TerminalPage::_HandleNewTab });
        _actionDispatch->SwitchToTab({ this, &TerminalPage::_HandleSwitchToTab });
        _actionDispatch->ResizePane({ this, &TerminalPage::_HandleResizePane });
        _actionDispatch->MoveFocus({ this, &TerminalPage::_HandleMoveFocus });
        _actionDispatch->CopyText({ this, &TerminalPage::_HandleCopyText });
        _actionDispatch->AdjustFontSize({ this, &TerminalPage::_HandleAdjustFontSize });
        _actionDispatch->Find({ this, &TerminalPage::_HandleFind });
        _actionDispatch->ResetFontSize({ this, &TerminalPage::_HandleResetFontSize });
        _actionDispatch->ToggleShaderEffects({ this, &TerminalPage::_HandleToggleShaderEffects });
        _actionDispatch->ToggleFocusMode({ this, &TerminalPage::_HandleToggleFocusMode });
        _actionDispatch->ToggleFullscreen({ this, &TerminalPage::_HandleToggleFullscreen });
        _actionDispatch->ToggleAlwaysOnTop({ this, &TerminalPage::_HandleToggleAlwaysOnTop });
        _actionDispatch->ToggleCommandPalette({ this, &TerminalPage::_HandleToggleCommandPalette });
        _actionDispatch->SetColorScheme({ this, &TerminalPage::_HandleSetColorScheme });
        _actionDispatch->SetTabColor({ this, &TerminalPage::_HandleSetTabColor });
        _actionDispatch->OpenTabColorPicker({ this, &TerminalPage::_HandleOpenTabColorPicker });
        _actionDispatch->RenameTab({ this, &TerminalPage::_HandleRenameTab });
        _actionDispatch->OpenTabRenamer({ this, &TerminalPage::_HandleOpenTabRenamer });
        _actionDispatch->ExecuteCommandline({ this, &TerminalPage::_HandleExecuteCommandline });
        _actionDispatch->CloseOtherTabs({ this, &TerminalPage::_HandleCloseOtherTabs });
        _actionDispatch->CloseTabsAfter({ this, &TerminalPage::_HandleCloseTabsAfter });
        _actionDispatch->TabSearch({ this, &TerminalPage::_HandleOpenTabSearch });
        _actionDispatch->MoveTab({ this, &TerminalPage::_HandleMoveTab });
        _actionDispatch->BreakIntoDebugger({ this, &TerminalPage::_HandleBreakIntoDebugger });
    }

    // Method Description:
    // - Get the title of the currently focused terminal control. If this tab is
    //   the focused tab, then also bubble this title to any listeners of our
    //   TitleChanged event.
    // Arguments:
    // - tab: the Tab to update the title for.
    void TerminalPage::_UpdateTitle(const TerminalTab& tab)
    {
        auto newTabTitle = tab.Title();

        if (_settings.GlobalSettings().ShowTitleInTitlebar() &&
            tab.FocusState() != FocusState::Unfocused)
        {
            _titleChangeHandlers(*this, newTabTitle);
        }
    }

    // Method Description:
    // - Get the icon of the currently focused terminal control, and set its