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

Code before:
                    // if the endpoint is outside of the viewport,
                    // just hide the markers
                    marker.Visibility(Visibility::Collapsed);
                    otherMarker.Visibility(Visibility::Collapsed);
                    co_return;
                }
                else if (_core.MovingCursor())
                {
                    // display both markers
                    displayMarker(true);
                    displayMarker(false);
                }
                else
                {
                    // display one marker,
                    // but hide the other
                    displayMarker(movingEnd);
                    otherMarker.Visibility(Visibility::Collapsed);
                }
            }
            else
            {
                // hide selection markers
                SelectionStartMarker().Visibility(Visibility::Collapsed);
                SelectionEndMarker().Visibility(Visibility::Collapsed);
            }
        }
    }

    til::point TermControl::_toPosInDips(const Core::Point terminalCellPos)
    {
        const til::point terminalPos{ terminalCellPos };
        const til::size marginsInDips{ til::math::rounding, GetPadding().Left, GetPadding().Top };
        const til::size fontSize{ til::math::rounding, _core.FontSize() };
        const til::point posInPixels{ terminalPos * fontSize };
        const auto scale{ SwapChainPanel().CompositionScaleX() };
        const til::point posInDIPs{ til::math::flooring, posInPixels.x / scale, posInPixels.y / scale };
        return posInDIPs + marginsInDips;
    }

    void TermControl::_coreFontSizeChanged(const int fontWidth,
                                           const int fontHeight,
                                           const bool isInitialChange)
    {
        // scale the selection markers to be the size of a cell
        auto scaleMarker = [fontWidth, fontHeight](Windows::UI::Xaml::Shapes::Path shape) {
            // The selection markers were designed to be 5x14 in size,
            // so use those dimensions below for the scaling
            const auto scaleX = fontWidth / 5.0;
            const auto scaleY = fontHeight / 14.0;


Review comment (suggestion):
cases where there is a selection, but `ClearMarkers==true`:
* Mouse selection, via `SetEndSelectionPoint`
* `LeftClickOnTerminal`, pretty self-explanatory
* A selection created from searching for text

okay those all make sense

Code after:

                    // Set the border thickness so it covers the entire cell
                    const auto charSizeInPixels = CharacterDimensions();
                    const auto htInDips = charSizeInPixels.Height / scale;
                    const auto wtInDips = charSizeInPixels.Width / scale;
                    const Thickness newThickness{ wtInDips, htInDips, 0, 0 };
                    HyperlinkTooltipBorder().BorderThickness(newThickness);

                    // Compute the location of the top left corner of the cell in DIPS
                    const til::point locationInDIPs{ _toPosInDips(lastHoveredCell.Value()) };

                    // Move the border to the top left corner of the cell
                    OverlayCanvas().SetLeft(HyperlinkTooltipBorder(), locationInDIPs.x - offset.x);
                    OverlayCanvas().SetTop(HyperlinkTooltipBorder(), locationInDIPs.y - offset.y);
                }
            }
        }
    }

    winrt::fire_and_forget TermControl::_updateSelectionMarkers(IInspectable /*sender*/, Control::UpdateSelectionMarkersEventArgs args)
    {
        auto weakThis{ get_weak() };
        co_await resume_foreground(Dispatcher());
        if (weakThis.get() && args)
        {
            if (_core.HasSelection() && !args.ClearMarkers())
            {
                // retrieve all of the necessary selection marker data
                // from the TerminalCore layer under one lock to improve performance
                const auto markerData{ _core.SelectionInfo() };

                // lambda helper function that can be used to display a selection marker
                // - targetEnd: if true, target the "end" selection marker. Otherwise, target "start".
                auto displayMarker = [&](bool targetEnd) {
                    const auto flipMarker{ targetEnd ? markerData.EndAtRightBoundary : markerData.StartAtLeftBoundary };
                    const auto& marker{ targetEnd ? SelectionEndMarker() : SelectionStartMarker() };

                    // Ensure the marker is oriented properly
                    // (i.e. if start is at the beginning of the buffer, it should be flipped)
                    auto transform{ marker.RenderTransform().as<Windows::UI::Xaml::Media::ScaleTransform>() };
                    transform.ScaleX(std::abs(transform.ScaleX()) * (flipMarker ? -1.0 : 1.0));
                    marker.RenderTransform(transform);

                    // Compute the location of the top left corner of the cell in DIPS
                    auto terminalPos{ targetEnd ? markerData.EndPos : markerData.StartPos };
                    if (flipMarker)
                    {
                        // When we flip the marker, a negative scaling makes us be one cell-width to the left.
                        // Add one to the viewport pos' x-coord to fix that.
                        terminalPos.X += 1;
                    }