diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 1122dd48d98..f6f1178fbc8 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -20,6 +20,10 @@ using namespace winrt::Windows::UI::Core; using namespace winrt::Windows::System; using namespace winrt::Microsoft::Terminal::Settings; +// Limit the rate of scroll update operation +// See also: Microsoft::Console::Render::RenderThread::s_FrameLimitMilliseconds +constexpr long long ScrollRateLimitMilliseconds = 8; + namespace winrt::Microsoft::Terminal::TerminalControl::implementation { // Helper static function to ensure that all ambiguous-width glyphs are reported as narrow. @@ -54,6 +58,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation _settings{ settings }, _closing{ false }, _lastScrollOffset{ std::nullopt }, + _lastScrollTime{ std::nullopt }, _autoScrollVelocity{ 0 }, _autoScrollingPointerPoint{ std::nullopt }, _autoScrollTimer{}, @@ -1412,6 +1417,21 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation return; } + // Throttle the update operation. + const auto timeNow = std::chrono::high_resolution_clock::now(); + + if (_lastScrollTime.has_value()) + { + const long long deltaTimeInMilliSec = std::chrono::duration_cast(timeNow - _lastScrollTime.value()).count(); + if (deltaTimeInMilliSec < ScrollRateLimitMilliseconds) + { + _lastScrollTime = std::nullopt; + return; + } + } + + _lastScrollTime = timeNow; + // Update our scrollbar _scrollBar.Dispatcher().RunAsync(CoreDispatcherPriority::Low, [=]() { // Even if we weren't closed/closing few lines above, we might be diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index 146ae5f222d..972e10f9abe 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -113,6 +113,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation FontInfo _actualFont; std::optional _lastScrollOffset; + std::optional _lastScrollTime; // Auto scroll occurs when user, while selecting, drags cursor outside viewport. View is then scrolled to 'follow' the cursor. double _autoScrollVelocity;