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

Code before:
    {
        _tabStatus.IsInputBroadcastActive(!_tabStatus.IsInputBroadcastActive());

        const bool isBroadcasting = _tabStatus.IsInputBroadcastActive();
        _rootPane->EnableBroadcast(isBroadcasting);

        auto weakThis{ get_weak() };

        // When we change the state of broadcasting, add or remove event
        // handlers appropriately, so that controls won't be propagating events
        // needlessly if no one is listening.

        _rootPane->WalkTree([&](const auto& p) {
            const auto paneId = p->Id();
            if (!paneId.has_value())
            {
                return;
            }
            if (const auto& control{ p->GetTerminalControl() })
            {
                auto it = _controlEvents.find(*paneId);
                if (it != _controlEvents.end())
                {
                    auto& events = it->second;

                    if (isBroadcasting)
                    {
                        // ADD EVENT HANDLERS HERE
                        events.keySentToken = control.KeySent([weakThis](auto&& sender, auto&& e) {
                            if (const auto tab{ weakThis.get() })
                            {
                                if (tab->_tabStatus.IsInputBroadcastActive())
                                {
                                    if (const auto termControl{ sender.try_as<winrt::Microsoft::Terminal::Control::TermControl>() })
                                    {
                                        tab->_rootPane->BroadcastKey(termControl, e.VKey(), e.ScanCode(), e.Modifiers(), e.KeyDown());
                                    }
                                }
                            }
                        });

                        events.charSentToken = control.CharSent([weakThis](auto&& sender, auto&& e) {
                            if (const auto tab{ weakThis.get() })
                            {
                                if (tab->_tabStatus.IsInputBroadcastActive())
                                {
                                    if (const auto termControl{ sender.try_as<winrt::Microsoft::Terminal::Control::TermControl>() })
                                    {
                                        tab->_rootPane->BroadcastChar(termControl, e.Character(), e.ScanCode(), e.Modifiers());
                                    }
                                }

Review comment (suggestion):
If you take the above,

```suggestion
                    if (newIsBroadcasting)
```

Code after:
    }

    // Method Description:
    // - Toggle broadcasting input to all the panes in this tab.
    void TerminalTab::ToggleBroadcastInput()
    {
        const bool newIsBroadcasting = !_tabStatus.IsInputBroadcastActive();
        _tabStatus.IsInputBroadcastActive(newIsBroadcasting);
        _rootPane->EnableBroadcast(newIsBroadcasting);

        auto weakThis{ get_weak() };

        // When we change the state of broadcasting, add or remove event
        // handlers appropriately, so that controls won't be propagating events
        // needlessly if no one is listening.

        _rootPane->WalkTree([&](const auto& p) {
            const auto paneId = p->Id();
            if (!paneId.has_value())
            {
                return;
            }
            if (const auto& control{ p->GetTerminalControl() })
            {
                auto it = _controlEvents.find(*paneId);
                if (it != _controlEvents.end())
                {
                    auto& events = it->second;

                    // Always clear out old ones, just in case.
                    events.KeySent.revoke();
                    events.CharSent.revoke();
                    events.StringSent.revoke();

                    if (newIsBroadcasting)
                    {
                        _addBroadcastHandlers(control, events);
                    }
                }
            }
        });
    }

    void TerminalTab::_addBroadcastHandlers(const TermControl& termControl, ControlEventTokens& events)
    {
        auto weakThis{ get_weak() };
        // ADD EVENT HANDLERS HERE
        events.KeySent = termControl.KeySent(winrt::auto_revoke, [weakThis](auto&& sender, auto&& e) {
            if (const auto tab{ weakThis.get() })
            {
                if (tab->_tabStatus.IsInputBroadcastActive())