@@ -44,6 +44,7 @@ namespace ControlUnitTests
44
44
TEST_METHOD (AltBufferClampMouse);
45
45
46
46
TEST_METHOD (CopyOnSelectSimple);
47
+ TEST_METHOD (CopyOnSelectAltBuffer);
47
48
48
49
TEST_CLASS_SETUP (ClassSetup)
49
50
{
@@ -971,8 +972,6 @@ namespace ControlUnitTests
971
972
972
973
void ControlInteractivityTests::CopyOnSelectSimple ()
973
974
{
974
- WEX::TestExecution::DisableVerifyExceptions disableVerifyExceptions{};
975
-
976
975
auto [settings, conn] = _createSettingsAndConnection ();
977
976
settings->CopyOnSelect (true );
978
977
auto [core, interactivity] = _createCoreAndInteractivity (*settings, *conn);
@@ -985,34 +984,113 @@ namespace ControlUnitTests
985
984
conn->WriteInput (winrt::hstring{ fmt::format (L" line {}\r\n " , i) });
986
985
}
987
986
987
+ // A callback for checking Copy events. expectedCopyContents=nullopt
988
+ // indicates that we're not expecting any copy events.
988
989
std::optional<std::wstring> expectedCopyContents{ std::nullopt };
989
990
core->CopyToClipboard ([&](auto &&, auto & args) {
990
991
VERIFY_IS_TRUE (expectedCopyContents.has_value ());
991
992
const std::wstring expected{ expectedCopyContents->c_str () };
992
993
const std::wstring actual{ args.Text ().c_str () };
993
994
VERIFY_ARE_EQUAL (expected, actual);
994
995
});
995
- // Start checking output
996
- // std::deque<std::wstring> expectedOutput{};
997
- // auto validateDrained = _addInputCallback(conn, expectedOutput);
996
+ bool expectedPaste = false ;
997
+ interactivity->PasteFromClipboard ([&](auto &&, auto &&) {
998
+ VERIFY_IS_TRUE (expectedPaste);
999
+ });
1000
+
1001
+ const auto originalViewport{ term.GetViewport () };
1002
+ VERIFY_ARE_EQUAL (originalViewport.Width (), 30 );
1003
+
1004
+ // For this test, don't use any modifiers
1005
+ const auto modifiers = ControlKeyStates ();
1006
+ const auto leftMouseDown{ Control::MouseButtonState::IsLeftButtonDown };
1007
+ const auto rightMouseDown{ Control::MouseButtonState::IsRightButtonDown };
1008
+ const Control::MouseButtonState noMouseDown{};
1009
+ const til::size fontSize{ 9 , 21 };
1010
+ const til::point terminalPosition0{ 0 , 5 };
1011
+ const til::point terminalPosition1{ 5 , 5 };
1012
+ const auto cursorPosition0{ terminalPosition0 * fontSize };
1013
+ const auto cursorPosition1{ terminalPosition1 * fontSize };
1014
+
1015
+ Log::Comment (L" --- Click on the terminal at 0,5 ---" );
1016
+
1017
+ interactivity->PointerPressed (leftMouseDown,
1018
+ WM_LBUTTONDOWN, // pointerUpdateKind
1019
+ 0 , // timestamp
1020
+ modifiers,
1021
+ cursorPosition0.to_core_point ());
1022
+ VERIFY_IS_FALSE (core->HasSelection ());
1023
+
1024
+ Log::Comment (L" --- Drag to 5,5 ---" );
1025
+
1026
+ interactivity->PointerMoved (leftMouseDown,
1027
+ WM_LBUTTONDOWN, // pointerUpdateKind
1028
+ modifiers,
1029
+ true , // focused,
1030
+ cursorPosition1.to_core_point (),
1031
+ true ); // pointerPressedInBounds
1032
+ VERIFY_IS_TRUE (core->HasSelection ());
1033
+ // expectedCopyContents being nullopt here will ensure that we don't send the copy event till the pointer released
1034
+
1035
+ Log::Comment (L" --- Release the mouse --- " );
1036
+ expectedCopyContents = L" line 5" ;
1037
+ interactivity->PointerReleased (noMouseDown,
1038
+ WM_LBUTTONUP, // pointerUpdateKind
1039
+ modifiers,
1040
+ cursorPosition1.to_core_point ());
1041
+ VERIFY_IS_TRUE (core->HasSelection ());
1042
+
1043
+ Log::Comment (L" --- Right-click to paste --- " );
1044
+ expectedCopyContents = std::nullopt;
1045
+ expectedPaste = true ;
1046
+ interactivity->PointerPressed (rightMouseDown,
1047
+ WM_RBUTTONDOWN, // pointerUpdateKind
1048
+ 0 , // timestamp
1049
+ modifiers,
1050
+ cursorPosition1.to_core_point ());
1051
+ VERIFY_IS_FALSE (core->HasSelection ());
1052
+ }
1053
+
1054
+ void ControlInteractivityTests::CopyOnSelectAltBuffer ()
1055
+ {
1056
+ auto [settings, conn] = _createSettingsAndConnection ();
1057
+ settings->CopyOnSelect (true );
1058
+ auto [core, interactivity] = _createCoreAndInteractivity (*settings, *conn);
1059
+ _standardInit (core, interactivity);
1060
+ auto & term{ *core->_terminal };
1061
+
1062
+ Log::Comment (L" --- Switch to alt buffer ---" );
1063
+ term.Write (L" \x1b [?1049h" );
1064
+ auto returnToMain = wil::scope_exit ([&]() { term.Write (L" \x1b [?1049h" ); });
1065
+
1066
+ // Output some text
1067
+ auto i = 0 ;
1068
+ for (i = 0 ; i < core->ViewHeight () - 1 ; ++i)
1069
+ {
1070
+ conn->WriteInput (winrt::hstring{ fmt::format (L" line {}\r\n " , i) });
1071
+ }
1072
+
1073
+ // A callback for checking Copy events. expectedCopyContents=nullopt
1074
+ // indicates that we're not expecting any copy events.
1075
+ std::optional<std::wstring> expectedCopyContents{ std::nullopt };
1076
+ core->CopyToClipboard ([&](auto &&, auto & args) {
1077
+ VERIFY_IS_TRUE (expectedCopyContents.has_value ());
1078
+ const std::wstring expected{ expectedCopyContents->c_str () };
1079
+ const std::wstring actual{ args.Text ().c_str () };
1080
+ VERIFY_ARE_EQUAL (expected, actual);
1081
+ });
1082
+ bool expectedPaste = false ;
1083
+ interactivity->PasteFromClipboard ([&](auto &&, auto &&) {
1084
+ VERIFY_IS_TRUE (expectedPaste);
1085
+ });
998
1086
999
1087
const auto originalViewport{ term.GetViewport () };
1000
1088
VERIFY_ARE_EQUAL (originalViewport.Width (), 30 );
1001
1089
1002
- // Log::Comment(L" --- Enable mouse mode ---");
1003
- // term.Write(L"\x1b[?1000h");
1004
-
1005
- // Log::Comment(L" --- Click on the terminal ---");
1006
- // // Recall:
1007
- // //
1008
- // // > ! specifies the value 1. The upper left character position on
1009
- // // > the terminal is denoted as 1,1
1010
- // //
1011
- // // So 5 in our buffer is 32+5+1 = '&'
1012
- // expectedOutput.push_back(L"\x1b[M &&");
1013
1090
// For this test, don't use any modifiers
1014
1091
const auto modifiers = ControlKeyStates ();
1015
1092
const auto leftMouseDown{ Control::MouseButtonState::IsLeftButtonDown };
1093
+ const auto rightMouseDown{ Control::MouseButtonState::IsRightButtonDown };
1016
1094
const Control::MouseButtonState noMouseDown{};
1017
1095
const til::size fontSize{ 9 , 21 };
1018
1096
const til::point terminalPosition0{ 0 , 5 };
@@ -1027,7 +1105,6 @@ namespace ControlUnitTests
1027
1105
0 , // timestamp
1028
1106
modifiers,
1029
1107
cursorPosition0.to_core_point ());
1030
- // VERIFY_ARE_EQUAL(0u, expectedOutput.size(), L"Validate we drained all the expected output");
1031
1108
VERIFY_IS_FALSE (core->HasSelection ());
1032
1109
1033
1110
Log::Comment (L" --- Drag to 5,5 ---" );
@@ -1048,5 +1125,21 @@ namespace ControlUnitTests
1048
1125
modifiers,
1049
1126
cursorPosition1.to_core_point ());
1050
1127
VERIFY_IS_TRUE (core->HasSelection ());
1128
+
1129
+ // Output some text
1130
+ for (; i < 5 ; ++i)
1131
+ {
1132
+ conn->WriteInput (winrt::hstring{ fmt::format (L" line {}\r\n " , i) });
1133
+ }
1134
+
1135
+ Log::Comment (L" --- Right-click to paste --- " );
1136
+ expectedCopyContents = std::nullopt;
1137
+ expectedPaste = true ;
1138
+ interactivity->PointerPressed (rightMouseDown,
1139
+ WM_RBUTTONDOWN, // pointerUpdateKind
1140
+ 0 , // timestamp
1141
+ modifiers,
1142
+ cursorPosition1.to_core_point ());
1143
+ VERIFY_IS_FALSE (core->HasSelection ());
1051
1144
}
1052
1145
}
0 commit comments