Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Alternate Scroll Mode when DECCKM enabled #5081

Merged
2 commits merged into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/terminal/adapter/ut_adapter/MouseInputTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,44 @@ class MouseInputTest
NoThrowString().Format(L"(x,y)=(%d,%d)", Coord.X, Coord.Y));
}
}

TEST_METHOD(AlternateScrollModeTests)
{
Log::Comment(L"Starting test...");
std::unique_ptr<TerminalInput> mouseInput = std::make_unique<TerminalInput>(s_MouseInputTestCallback);
const short noModifierKeys = 0;

Log::Comment(L"Enable alternate scroll mode in the alt screen buffer");
mouseInput->UseAlternateScreenBuffer();
mouseInput->EnableAlternateScroll(true);

Log::Comment(L"Test mouse wheel scrolling up");
s_pwszInputExpected = L"\x1B[A";
VERIFY_IS_TRUE(mouseInput->HandleMouse({ 0, 0 }, WM_MOUSEWHEEL, noModifierKeys, 1));

Log::Comment(L"Test mouse wheel scrolling down");
s_pwszInputExpected = L"\x1B[B";
VERIFY_IS_TRUE(mouseInput->HandleMouse({ 0, 0 }, WM_MOUSEWHEEL, noModifierKeys, -1));

Log::Comment(L"Enable cursor keys mode");
mouseInput->ChangeCursorKeysMode(true);

Log::Comment(L"Test mouse wheel scrolling up");
s_pwszInputExpected = L"\x1BOA";
VERIFY_IS_TRUE(mouseInput->HandleMouse({ 0, 0 }, WM_MOUSEWHEEL, noModifierKeys, 1));

Log::Comment(L"Test mouse wheel scrolling down");
s_pwszInputExpected = L"\x1BOB";
VERIFY_IS_TRUE(mouseInput->HandleMouse({ 0, 0 }, WM_MOUSEWHEEL, noModifierKeys, -1));

Log::Comment(L"Confirm no effect when scroll mode is disabled");
mouseInput->UseAlternateScreenBuffer();
mouseInput->EnableAlternateScroll(false);
VERIFY_IS_FALSE(mouseInput->HandleMouse({ 0, 0 }, WM_MOUSEWHEEL, noModifierKeys, 1));

Log::Comment(L"Confirm no effect when using the main buffer");
mouseInput->UseMainScreenBuffer();
mouseInput->EnableAlternateScroll(true);
VERIFY_IS_FALSE(mouseInput->HandleMouse({ 0, 0 }, WM_MOUSEWHEEL, noModifierKeys, 1));
}
};
6 changes: 4 additions & 2 deletions src/terminal/input/mouseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ static constexpr short KeyPressed{ gsl::narrow_cast<short>(0x8000) };
// Alternate scroll sequences
static constexpr std::wstring_view CursorUpSequence{ L"\x1b[A" };
static constexpr std::wstring_view CursorDownSequence{ L"\x1b[B" };
static constexpr std::wstring_view ApplicationUpSequence{ L"\x1bOA" };
static constexpr std::wstring_view ApplicationDownSequence{ L"\x1bOB" };

// Routine Description:
// - Determines if the input windows message code describes a button event
Expand Down Expand Up @@ -523,11 +525,11 @@ bool TerminalInput::_SendAlternateScroll(const short delta) const noexcept
{
if (delta > 0)
{
_SendInputSequence(CursorUpSequence);
_SendInputSequence(_cursorApplicationMode ? ApplicationUpSequence : CursorUpSequence);
}
else
{
_SendInputSequence(CursorDownSequence);
_SendInputSequence(_cursorApplicationMode ? ApplicationDownSequence : CursorDownSequence);
}
return true;
}