Repository: microsoft/terminal
File: src/cascadia/TerminalControl/TermControl.cpp (C++)

Code before:
                r.Width(16.0f / 3.0f); // pip width - 1/3rd of the scrollbar width.
                r.Height(2);
                const auto fractionalHeight = row / totalBufferRows;
                const auto relativePos = fractionalHeight * fullHeight;
                ScrollBarCanvas().Children().Append(r);
                Windows::UI::Xaml::Controls::Canvas::SetTop(r, relativePos);
                if (rightAlign)
                {
                    Windows::UI::Xaml::Controls::Canvas::SetLeft(r, 16.0f * .66f);
                }
            };

            for (const auto m : marks)
            {
                Windows::UI::Xaml::Shapes::Rectangle r;
                Media::SolidColorBrush brush{};
                // Sneaky: technically, a mark doesn't need to have a color set,
                // it might want to just use the color from the palette for that
                // kind of mark. Fortunately, ControlCore is kind enough to
                // pre-evaluate that for us, and shove the real value into the
                // Color member, regardless if the mark has a literal value set.
                brush.Color(static_cast<til::color>(m.Color.Color));
                drawPip(m.Start.Y, false, brush);
            }

            auto searchMatches{ _core.MatchRows() };
            if (searchMatches.Size() > 0 && _searchBox->Visibility() == Visibility::Visible)
            {
                auto fgColor{ _core.ForegroundColor() };
                Media::SolidColorBrush searchMarkBrush{};
                searchMarkBrush.Color(static_cast<til::color>(fgColor));
                for (const auto m : searchMatches)
                {
                    drawPip(m, true, searchMarkBrush);
                }
            }
        }
    }

    // Method Description:
    // - Loads the search box from the xaml UI and focuses it.
    void TermControl::CreateSearchBoxControl()
    {
        // Lazy load the search box control.
        if (auto loadedSearchBox{ FindName(L"SearchBox") })
        {
            if (auto searchBox{ loadedSearchBox.try_as<::winrt::Microsoft::Terminal::Control::SearchBoxControl>() })
            {
                // get at its private implementation
                _searchBox.copy_from(winrt::get_self<implementation::SearchBoxControl>(searchBox));
                _searchBox->Visibility(Visibility::Visible);

Review comment (suggestion):
```suggestion
            const auto searchMatches{ _core.MatchRows() };
```

Code after:
        _originalSecondaryElements = winrt::single_threaded_observable_vector<Controls::ICommandBarElement>();
        _originalSelectedPrimaryElements = winrt::single_threaded_observable_vector<Controls::ICommandBarElement>();
        _originalSelectedSecondaryElements = winrt::single_threaded_observable_vector<Controls::ICommandBarElement>();
        for (const auto& e : ContextMenu().PrimaryCommands())
        {
            _originalPrimaryElements.Append(e);
        }
        for (const auto& e : ContextMenu().SecondaryCommands())
        {
            _originalSecondaryElements.Append(e);
        }
        for (const auto& e : SelectionContextMenu().PrimaryCommands())
        {
            _originalSelectedPrimaryElements.Append(e);
        }
        for (const auto& e : SelectionContextMenu().SecondaryCommands())
        {
            _originalSelectedSecondaryElements.Append(e);
        }
        ContextMenu().Closed([weakThis = get_weak()](auto&&, auto&&) {
            if (auto control{ weakThis.get() }; !control->_IsClosing())
            {
                const auto& menu{ control->ContextMenu() };
                menu.PrimaryCommands().Clear();
                menu.SecondaryCommands().Clear();
                for (const auto& e : control->_originalPrimaryElements)
                {
                    menu.PrimaryCommands().Append(e);
                }
                for (const auto& e : control->_originalSecondaryElements)
                {
                    menu.SecondaryCommands().Append(e);
                }
            }
        });
        SelectionContextMenu().Closed([weakThis = get_weak()](auto&&, auto&&) {
            if (auto control{ weakThis.get() }; !control->_IsClosing())
            {
                const auto& menu{ control->SelectionContextMenu() };
                menu.PrimaryCommands().Clear();
                menu.SecondaryCommands().Clear();
                for (const auto& e : control->_originalSelectedPrimaryElements)
                {
                    menu.PrimaryCommands().Append(e);
                }
                for (const auto& e : control->_originalSelectedSecondaryElements)
                {
                    menu.SecondaryCommands().Append(e);
                }
            }
        });