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

Send an updated cursor position at the end of writing a run #12210

Merged
8 commits merged into from Jan 25, 2022
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/Terminal.cpp
Expand Up @@ -989,6 +989,7 @@ void Terminal::_WriteBuffer(const std::wstring_view& stringView)
}

cursor.EndDeferDrawing();
_NotifyTerminalCursorPositionChanged();
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
}

void Terminal::_AdjustCursorPosition(const COORD proposedPosition)
Expand Down
41 changes: 41 additions & 0 deletions src/cascadia/UnitTests_TerminalCore/TerminalBufferTests.cpp
Expand Up @@ -51,6 +51,8 @@ class TerminalCoreUnitTests::TerminalBufferTests final

TEST_METHOD(TestGetReverseTab);

TEST_METHOD(TestCursorNotifications);

TEST_METHOD_SETUP(MethodSetup)
{
// STEP 1: Set up the Terminal
Expand Down Expand Up @@ -592,3 +594,42 @@ void TerminalBufferTests::TestGetReverseTab()
L"Cursor adjusted to last item in the sample list from position beyond end.");
}
}

void TerminalBufferTests::TestCursorNotifications()
{
// Test for GH#11170

// Suppress test exceptions. If they occur in the lambda, they'll just crash
// TAEF, which is annoying.
const WEX::TestExecution::DisableVerifyExceptions disableExceptionsScope;

bool callbackWasCalled = false;
int expectedCallbacks = 0;
auto cb = [&expectedCallbacks, &callbackWasCalled]() mutable {
Log::Comment(L"Callback triggered");
callbackWasCalled = true;
expectedCallbacks--;
VERIFY_IS_GREATER_THAN_OR_EQUAL(expectedCallbacks, 0);
// VERIFY_IS_TRUE(expectedCallbacks >= 0);
};
term->_pfnCursorPositionChanged = cb;

expectedCallbacks = 1;
callbackWasCalled = false;
term->_WriteBuffer(L"Foo");
VERIFY_ARE_EQUAL(0, expectedCallbacks);
VERIFY_IS_TRUE(callbackWasCalled);

expectedCallbacks = 1;
callbackWasCalled = false;
term->_WriteBuffer(L"Foo\r\nBar");
VERIFY_ARE_EQUAL(0, expectedCallbacks);
VERIFY_IS_TRUE(callbackWasCalled);

expectedCallbacks = 2;
callbackWasCalled = false;
term->_WriteBuffer(L"Foo\r\nBar");
term->_WriteBuffer(L"Foo\r\nBar");
VERIFY_ARE_EQUAL(0, expectedCallbacks);
VERIFY_IS_TRUE(callbackWasCalled);
}