Repository: microsoft/terminal
File: src/cascadia/UnitTests_Control/ControlInteractivityTests.cpp (C++)

Code before:
            VERIFY_ARE_EQUAL(expectedAnchor, end);
        }
        VERIFY_ARE_EQUAL(scrollbackLength - 1, core->_terminal->GetScrollOffset());

        Log::Comment(L"Output a line of text");
        conn->WriteInput(L"Foo\r\n");

        Log::Comment(L"Verify the location of the selection");
        // The selection should now be 1 row lower
        expectedAnchor.y -= 1;
        {
            const auto anchor{ core->_terminal->GetSelectionAnchor() };
            const auto end{ core->_terminal->GetSelectionEnd() };
            Log::Comment(fmt::format(L"expectedAnchor:({},{})", expectedAnchor.x, expectedAnchor.y).c_str());
            Log::Comment(fmt::format(L"anchor:({},{})", anchor.x, anchor.y).c_str());
            Log::Comment(fmt::format(L"end:({},{})", end.x, end.y).c_str());

            VERIFY_ARE_EQUAL(expectedAnchor, anchor);
            VERIFY_ARE_EQUAL(expectedAnchor, end);
        }
        VERIFY_ARE_EQUAL(scrollbackLength - 2, core->_terminal->GetScrollOffset());

        Log::Comment(L"Move the mouse a little, to update the selection");
        // At this point, there should only be one selection region! The
        // viewport moved up to keep the selection at the same relative spot. So
        // wiggling the cursor shoudld continue to select only the same
        // character in the buffer (if, albeit in a new location).
        //
        // This helps test GH #14462, a regression from #10749.
        interactivity->PointerMoved(leftMouseDown,
                                    WM_LBUTTONDOWN, //pointerUpdateKind
                                    modifiers,
                                    true, // focused,
                                    cursorPosition0.to_core_point(),
                                    true);
        VERIFY_IS_TRUE(core->HasSelection());
        VERIFY_ARE_EQUAL(1u, core->_terminal->GetSelectionRects().size());
        {
            const auto anchor{ core->_terminal->GetSelectionAnchor() };
            const auto end{ core->_terminal->GetSelectionEnd() };
            Log::Comment(fmt::format(L"expectedAnchor:({},{})", expectedAnchor.x, expectedAnchor.y).c_str());
            Log::Comment(fmt::format(L"anchor:({},{})", anchor.x, anchor.y).c_str());
            Log::Comment(fmt::format(L"end:({},{})", end.x, end.y).c_str());

            VERIFY_ARE_EQUAL(expectedAnchor, anchor);
            VERIFY_ARE_EQUAL(expectedAnchor, end);
        }

        Log::Comment(L"Output a line ant move the mouse a little to update the selection, all at once");
        // Same as above. The viewport has moved, so the mouse is still over the
        // same character, even though it's at a new offset.

Review comment (suggestion):
```suggestion
        // wiggling the cursor should continue to select only the same
```

Code after:
            VERIFY_ARE_EQUAL(expectedAnchor, end);
        }
        VERIFY_ARE_EQUAL(scrollbackLength - 1, core->_terminal->GetScrollOffset());

        Log::Comment(L"Output a line of text");
        conn->WriteInput(L"Foo\r\n");

        Log::Comment(L"Verify the location of the selection");
        // The selection should now be 1 row lower
        expectedAnchor.y -= 1;
        {
            const auto anchor{ core->_terminal->GetSelectionAnchor() };
            const auto end{ core->_terminal->GetSelectionEnd() };
            Log::Comment(fmt::format(L"expectedAnchor:({},{})", expectedAnchor.x, expectedAnchor.y).c_str());
            Log::Comment(fmt::format(L"anchor:({},{})", anchor.x, anchor.y).c_str());
            Log::Comment(fmt::format(L"end:({},{})", end.x, end.y).c_str());

            VERIFY_ARE_EQUAL(expectedAnchor, anchor);
            VERIFY_ARE_EQUAL(expectedAnchor, end);
        }
        VERIFY_ARE_EQUAL(scrollbackLength - 2, core->_terminal->GetScrollOffset());

        Log::Comment(L"Move the mouse a little, to update the selection");
        // At this point, there should only be one selection region! The
        // viewport moved up to keep the selection at the same relative spot. So
        // wiggling the cursor should continue to select only the same
        // character in the buffer (if, albeit in a new location).
        //
        // This helps test GH #14462, a regression from #10749.
        interactivity->PointerMoved(leftMouseDown,
                                    WM_LBUTTONDOWN, //pointerUpdateKind
                                    modifiers,
                                    true, // focused,
                                    cursorPosition0.to_core_point(),
                                    true);
        VERIFY_IS_TRUE(core->HasSelection());
        VERIFY_ARE_EQUAL(1u, core->_terminal->GetSelectionRects().size());
        {
            const auto anchor{ core->_terminal->GetSelectionAnchor() };
            const auto end{ core->_terminal->GetSelectionEnd() };
            Log::Comment(fmt::format(L"expectedAnchor:({},{})", expectedAnchor.x, expectedAnchor.y).c_str());
            Log::Comment(fmt::format(L"anchor:({},{})", anchor.x, anchor.y).c_str());
            Log::Comment(fmt::format(L"end:({},{})", end.x, end.y).c_str());

            VERIFY_ARE_EQUAL(expectedAnchor, anchor);
            VERIFY_ARE_EQUAL(expectedAnchor, end);
        }

        Log::Comment(L"Output a line ant move the mouse a little to update the selection, all at once");
        // Same as above. The viewport has moved, so the mouse is still over the
        // same character, even though it's at a new offset.