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

Code before:
    {
        _core.Search(text, goForward, caseSensitive);
    }

    // Method Description:
    // - The handler for the "search criteria changed" event. Clears selection and initiates a new search.
    // Arguments:
    // - text: the text to search
    // - goForward: indicates whether the search should be performed forward (if set to true) or backward
    // - caseSensitive: boolean that represents if the current search is case sensitive
    // Return Value:
    // - <none>
    void TermControl::_SearchChanged(const winrt::hstring& text,
                                     const bool goForward,
                                     const bool caseSensitive)
    {
        if (_searchBox && _searchBox->Visibility() == Visibility::Visible)
        {
            _core.SearchChanged(text, goForward, caseSensitive);
        }
    }

    // Method Description:
    // - The handler for the close button or pressing "Esc" when focusing on the
    //   search dialog.
    // Arguments:
    // - IInspectable: not used
    // - RoutedEventArgs: not used
    // Return Value:
    // - <none>
    void TermControl::_CloseSearchBoxControl(const winrt::Windows::Foundation::IInspectable& /*sender*/,
                                             const RoutedEventArgs& /*args*/)
    {
        _searchBox->Visibility(Visibility::Collapsed);
        _core.ExitSearch();

        // Set focus back to terminal control
        this->Focus(FocusState::Programmatic);
    }

    winrt::fire_and_forget TermControl::UpdateControlSettings(IControlSettings settings)
    {
        return UpdateControlSettings(settings, _core.UnfocusedAppearance());
    }
    // Method Description:
    // - Given Settings having been updated, applies the settings to the current terminal.
    // Return Value:
    // - <none>
    winrt::fire_and_forget TermControl::UpdateControlSettings(IControlSettings settings, IControlAppearance unfocusedAppearance)
    {
        auto weakThis{ get_weak() };

Review comment (suggestion):
FYI this is where I think we could add our logic to avoid drawing too many of these. By multiplying by the display scale (not sure if that's needed) we can figure out if this pip would overlap with a previously drawn pip. I think the code for that should be somewhat easy... I think? We could use a lambda factory (a lambda that returns a lambda) to do that. Like this:
```cpp
const auto drawPipMaker = [&]() {
    double previousPos = 0;
    return [previousPos, &](const auto row, const auto rightAlign, const auto& brush) mutable {
         // This assumes that "row" is sorted (either ascending or descending).
         if (std::abs(newPos - previousPos) < onePixel)
         {
             return;
         }
         // ...
    };
};
// ...
auto drawPip = drawPipMaker();
// ...
auto drawPip = drawPipMaker();
// ...
```

Code after:
        {
            scrollBar.Value(*update.newValue);
        }
        scrollBar.Maximum(update.newMaximum);
        scrollBar.Minimum(update.newMinimum);
        scrollBar.ViewportSize(update.newViewportSize);
        // scroll one full screen worth at a time when the scroll bar is clicked
        scrollBar.LargeChange(std::max(update.newViewportSize - 1, 0.));

        _isInternalScrollBarUpdate = false;

        if (_showMarksInScrollbar)
        {
            // Update scrollbar marks
            ScrollBarCanvas().Children().Clear();
            const auto marks{ _core.ScrollMarks() };
            const auto fullHeight{ ScrollBarCanvas().ActualHeight() };
            const auto totalBufferRows{ update.newMaximum + update.newViewportSize };

            auto drawPip = [&](const auto row, const auto rightAlign, const auto& brush) {
                Windows::UI::Xaml::Shapes::Rectangle r;
                r.Fill(brush);
                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);
            }

            if (_searchBox)
            {
                const auto searchMatches{ _core.SearchResultRows() };
                if (searchMatches &&