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

Code before:
        }
        else if (const auto& realArgs = args.ActionArgs().try_as<SendInputArgs>())
        {
            if (const auto termControl{ _GetActiveControl() })
            {
                termControl.SendInput(realArgs.Input());
                args.Handled(true);
            }
        }
    }

    void TerminalPage::_HandleCloseOtherPanes(const IInspectable& /*sender*/,
                                              const ActionEventArgs& args)
    {
        if (const auto terminalTab{ _GetFocusedTabImpl() })
        {
            const auto activePane = terminalTab->GetActivePane();
            if (terminalTab->GetRootPane() != activePane)
            {
                _UnZoomIfNeeded();

                // Accumulate list of all unfocused leaf panes
                std::vector<uint32_t> unfocusedPaneIds;
                terminalTab->GetRootPane()->WalkTree([&](auto&& p) {
                    const auto id = p->Id();
                    if (id.has_value() && id != activePane->Id())
                    {
                        unfocusedPaneIds.push_back(id.value());
                    }
                });

                // Start by removing the panes that were least recently added
                sort(begin(unfocusedPaneIds), end(unfocusedPaneIds), std::less<uint32_t>());
                _CloseUnfocusedPanes(terminalTab->get_weak(), std::move(unfocusedPaneIds));
            }
        }
        args.Handled(true);
    }

    void TerminalPage::_HandleMovePane(const IInspectable& /*sender*/,
                                       const ActionEventArgs& args)
    {
        if (args == nullptr)
        {
            args.Handled(false);
        }
        else if (const auto& realArgs = args.ActionArgs().try_as<MovePaneArgs>())
        {
            auto moved = _MovePane(realArgs.TabIndex());
            args.Handled(moved);
        }

Review comment (suggestion):
```suggestion
                const auto activePaneId = activePane->Id();
                terminalTab->GetRootPane()->WalkTree([&](auto&& p) {
                    const auto id = p->Id();
                    if (id.has_value() && id != activePaneId)
```
You can move the `activePane->Id()` into a variable and scope it in the lambda. That way, we only call it once.

Code after:
        }
        else if (const auto& realArgs = args.ActionArgs().try_as<SendInputArgs>())
        {
            if (const auto termControl{ _GetActiveControl() })
            {
                termControl.SendInput(realArgs.Input());
                args.Handled(true);
            }
        }
    }

    void TerminalPage::_HandleCloseOtherPanes(const IInspectable& /*sender*/,
                                              const ActionEventArgs& args)
    {
        if (const auto terminalTab{ _GetFocusedTabImpl() })
        {
            const auto activePane = terminalTab->GetActivePane();
            if (terminalTab->GetRootPane() != activePane)
            {
                _UnZoomIfNeeded();

                // Accumulate list of all unfocused leaf panes, ignore read-only panes
                std::vector<uint32_t> unfocusedPaneIds;
                const auto activePaneId = activePane->Id();
                terminalTab->GetRootPane()->WalkTree([&](auto&& p) {
                    const auto id = p->Id();
                    if (id.has_value() && id != activePaneId && !p->ContainsReadOnly())
                    {
                        unfocusedPaneIds.push_back(id.value());
                    }
                });

                if (!empty(unfocusedPaneIds))
                {
                    // Start by removing the panes that were least recently added
                    sort(begin(unfocusedPaneIds), end(unfocusedPaneIds), std::less<uint32_t>());
                    _ClosePanes(terminalTab->get_weak(), std::move(unfocusedPaneIds));
                    args.Handled(true);
                    return;
                }
            }
            args.Handled(false);
        }
    }

    void TerminalPage::_HandleMovePane(const IInspectable& /*sender*/,
                                       const ActionEventArgs& args)
    {
        if (args == nullptr)
        {
            args.Handled(false);