@@ -32,6 +32,7 @@ namespace ControlUnitTests
3232 TEST_METHOD (ScrollWithSelection);
3333 TEST_METHOD (TestScrollWithTrackpad);
3434 TEST_METHOD (TestQuickDragOnSelect);
35+ TEST_METHOD (PointerClickOutsideActiveRegion);
3536
3637 TEST_CLASS_SETUP (ClassSetup)
3738 {
@@ -542,4 +543,93 @@ namespace ControlUnitTests
542543 COORD expectedAnchor{ 0 , 0 };
543544 VERIFY_ARE_EQUAL (expectedAnchor, core->_terminal ->GetSelectionAnchor ());
544545 }
546+
547+ void ControlInteractivityTests::PointerClickOutsideActiveRegion ()
548+ {
549+ // This is a test for GH#10642
550+ WEX::TestExecution::DisableVerifyExceptions disableVerifyExceptions{};
551+
552+ auto [settings, conn] = _createSettingsAndConnection ();
553+ auto [core, interactivity] = _createCoreAndInteractivity (*settings, *conn);
554+ _standardInit (core, interactivity);
555+
556+ // For this test, don't use any modifiers
557+ const auto modifiers = ControlKeyStates ();
558+ const TerminalInput::MouseButtonState leftMouseDown{ true , false , false };
559+ const TerminalInput::MouseButtonState noMouseDown{ false , false , false };
560+
561+ const til::size fontSize{ 9 , 21 };
562+
563+ interactivity->_rowsToScroll = 1 ;
564+ int expectedTop = 0 ;
565+ int expectedViewHeight = 20 ;
566+ int expectedBufferHeight = 20 ;
567+
568+ auto scrollChangedHandler = [&](auto &&, const Control::ScrollPositionChangedArgs& args) mutable {
569+ VERIFY_ARE_EQUAL (expectedTop, args.ViewTop ());
570+ VERIFY_ARE_EQUAL (expectedViewHeight, args.ViewHeight ());
571+ VERIFY_ARE_EQUAL (expectedBufferHeight, args.BufferSize ());
572+ };
573+ core->ScrollPositionChanged (scrollChangedHandler);
574+ interactivity->ScrollPositionChanged (scrollChangedHandler);
575+
576+ for (int i = 0 ; i < 40 ; ++i)
577+ {
578+ Log::Comment (NoThrowString ().Format (L" Writing line #%d" , i));
579+ // The \r\n in the 19th loop will cause the view to start moving
580+ if (i >= 19 )
581+ {
582+ expectedTop++;
583+ expectedBufferHeight++;
584+ }
585+
586+ conn->WriteInput (L" Foo\r\n " );
587+ }
588+ // We printed that 40 times, but the final \r\n bumped the view down one MORE row.
589+ VERIFY_ARE_EQUAL (20 , core->_terminal ->GetViewport ().Height ());
590+ VERIFY_ARE_EQUAL (21 , core->ScrollOffset ());
591+ VERIFY_ARE_EQUAL (20 , core->ViewHeight ());
592+ VERIFY_ARE_EQUAL (41 , core->BufferHeight ());
593+
594+ expectedBufferHeight = 41 ;
595+ expectedTop = 21 ;
596+
597+ Log::Comment (L" Scroll up 10 times" );
598+ for (int i = 0 ; i < 11 ; ++i)
599+ {
600+ expectedTop--;
601+ interactivity->MouseWheel (modifiers,
602+ WHEEL_DELTA,
603+ til::point{ 0 , 0 },
604+ { false , false , false });
605+ }
606+
607+ // Enable VT mouse event tracking
608+ conn->WriteInput (L" \x1b [?1003;1006h" );
609+
610+ // Mouse clicks in the inactive region (i.e. the top 10 rows in this case) should not register
611+ Log::Comment (L" Click on the terminal" );
612+ const til::point terminalPosition0{ 4 , 4 };
613+ const til::point cursorPosition0 = terminalPosition0 * fontSize;
614+ interactivity->PointerPressed (leftMouseDown,
615+ WM_LBUTTONDOWN, // pointerUpdateKind
616+ 0 , // timestamp
617+ modifiers,
618+ cursorPosition0);
619+ Log::Comment (L" Verify that there's not yet a selection" );
620+
621+ VERIFY_IS_FALSE (core->HasSelection ());
622+
623+ Log::Comment (L" Drag the mouse" );
624+ // move the mouse as if to make a selection
625+ const til::point terminalPosition1{ 10 , 4 };
626+ const til::point cursorPosition1 = terminalPosition1 * fontSize;
627+ interactivity->PointerMoved (leftMouseDown,
628+ WM_LBUTTONDOWN, // pointerUpdateKind
629+ modifiers,
630+ true , // focused,
631+ cursorPosition1);
632+ Log::Comment (L" Verify that there's still no selection" );
633+ VERIFY_IS_FALSE (core->HasSelection ());
634+ }
545635}
0 commit comments