Repository: microsoft/terminal
File: src/cascadia/TerminalCore/TerminalSelection.cpp (C++)

Code before:
        // IMPORTANT! Pivoting the selection here might have changed which endpoint we're targeting.
        // So let's set the targeted endpoint again.
        WI_UpdateFlag(_selectionEndpoint, SelectionEndpoint::Start, targetStart);
        WI_UpdateFlag(_selectionEndpoint, SelectionEndpoint::End, !targetStart);
    }

    // 4. Scroll (if necessary)
    if (const auto visibleViewport = _GetVisibleViewport(); !visibleViewport.IsInBounds(targetPos))
    {
        if (const auto amtAboveView = visibleViewport.Top() - targetPos.Y; amtAboveView > 0)
        {
            // anchor is above visible viewport, scroll by that amount
            _scrollOffset += amtAboveView;
        }
        else
        {
            // anchor is below visible viewport, scroll by that amount
            const auto amtBelowView = targetPos.Y - visibleViewport.BottomInclusive();
            _scrollOffset -= amtBelowView;
        }
        _NotifyScrollEvent();
        _activeBuffer().TriggerScroll();
    }
}

void Terminal::SelectAll()
{
    const auto bufferSize{ _activeBuffer().GetSize() };
    _selection = SelectionAnchors{};
    _selection->start = bufferSize.Origin();
    _selection->end = { bufferSize.RightInclusive(), _GetMutableViewport().BottomInclusive() };
    _selection->pivot = _selection->end;
    _selectionMode = SelectionInteractionMode::Keyboard;
}

void Terminal::_MoveByChar(SelectionDirection direction, til::point& pos)
{
    switch (direction)
    {
    case SelectionDirection::Left:
        _activeBuffer().GetSize().DecrementInBounds(pos);
        pos = _activeBuffer().GetGlyphStart(pos);
        break;
    case SelectionDirection::Right:
        _activeBuffer().GetSize().IncrementInBounds(pos);
        pos = _activeBuffer().GetGlyphEnd(pos);
        break;
    case SelectionDirection::Up:
    {
        const auto bufferSize{ _activeBuffer().GetSize() };
        const auto newY{ pos.Y - 1 };

Review comment (suggestion):
when you make selection exclusive, rename `end` so things like this immediately become build breaks. you don't have to _keep_ the rename, just use it to highlight issues where we might be mistreating the endpoint!

Code after:
                if (dir == SearchDirection::Forward)
                {
                    searchStart.y += 1;
                    searchEnd.y = std::min(searchStart.y + viewportHeight, ViewEndIndex());
                }
                else
                {
                    searchEnd.y -= 1;
                    searchStart.y = std::max(searchEnd.y - viewportHeight, bufferSize.Top());
                }
                searchArea = Viewport::FromDimensions(searchStart, searchEnd.x + 1, searchEnd.y + 1);
            }
        }

        // 1.C) Nothing was found. Bail!
        if (!result.has_value())
        {
            return;
        }
    }

    // 2. Select the hyperlink
    _selection->start = result->first;
    _selection->pivot = result->first;
    _selection->end = result->second;
    bufferSize.DecrementInBounds(_selection->end);
    _isTargetingUrl = true;
    _selectionEndpoint = SelectionEndpoint::End;

    // 3. Scroll to the selected area (if necessary)
    _ScrollToPoint(_selection->end);
}

bool Terminal::IsTargetingUrl() const noexcept
{
    return _isTargetingUrl;
}

Terminal::UpdateSelectionParams Terminal::ConvertKeyEventToUpdateSelectionParams(const ControlKeyStates mods, const WORD vkey) const
{
    if ((_selectionMode == SelectionInteractionMode::Mark || mods.IsShiftPressed()) && !mods.IsAltPressed())
    {
        if (mods.IsCtrlPressed())
        {
            // Ctrl + Shift + _
            // (Mark Mode) Ctrl + _
            switch (vkey)
            {
            case VK_LEFT:
                return UpdateSelectionParams{ std::in_place, SelectionDirection::Left, SelectionExpansion::Word };
            case VK_RIGHT: