Skip to content

Commit

Permalink
Even cleaner solution
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jan 25, 2022
1 parent 67441eb commit d0fb6dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
20 changes: 14 additions & 6 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,21 @@ void Terminal::Write(std::wstring_view stringView)
{
auto lock = LockForWriting();

auto& cursor = _buffer->GetCursor();
const til::point cursorPosBefore{ cursor.GetPosition() };

_stateMachine->ProcessString(stringView);

const til::point cursorPosAfter{ cursor.GetPosition() };

// Firing the CursorPositionChanged event is very expensive so we try not to
// do that when the cursor does not need to be redrawn. We don't do this
// inside _AdjustCursorPosition, only once we're done writing the whole run
// of output.
if (cursorPosBefore != cursorPosAfter)
{
_NotifyTerminalCursorPositionChanged();
}
}

void Terminal::WritePastedText(std::wstring_view stringView)
Expand Down Expand Up @@ -989,12 +1003,6 @@ void Terminal::_WriteBuffer(const std::wstring_view& stringView)
}

cursor.EndDeferDrawing();

// Firing the CursorPositionChanged event is very expensive so we try not to
// do that when the cursor does not need to be redrawn. We don't do this
// inside _AdjustCursorPosition, only once we're done writing the whole run
// of output.
_NotifyTerminalCursorPositionChanged();
}

void Terminal::_AdjustCursorPosition(const COORD proposedPosition)
Expand Down
4 changes: 0 additions & 4 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ try
}
_AdjustCursorPosition(cursorPos);

// Send an updated cursor position event. See GH#12210 for why this is done
// here instead of in _AdjustCursorPosition
_NotifyTerminalCursorPositionChanged();

return true;
}
CATCH_RETURN_FALSE()
Expand Down
7 changes: 4 additions & 3 deletions src/cascadia/UnitTests_TerminalCore/TerminalBufferTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,23 +610,24 @@ void TerminalBufferTests::TestCursorNotifications()
callbackWasCalled = true;
expectedCallbacks--;
VERIFY_IS_GREATER_THAN_OR_EQUAL(expectedCallbacks, 0);
// VERIFY_IS_TRUE(expectedCallbacks >= 0);
};
term->_pfnCursorPositionChanged = cb;

// The exact number of callbacks here is fungible, if need be.

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

expectedCallbacks = 3; // one for foo, one for the newline, one for bar
expectedCallbacks = 1;
callbackWasCalled = false;
term->Write(L"Foo\r\nBar");
VERIFY_ARE_EQUAL(0, expectedCallbacks);
VERIFY_IS_TRUE(callbackWasCalled);

expectedCallbacks = 6;
expectedCallbacks = 2; // One for each Write
callbackWasCalled = false;
term->Write(L"Foo\r\nBar");
term->Write(L"Foo\r\nBar");
Expand Down

0 comments on commit d0fb6dd

Please sign in to comment.