diff --git a/src/cascadia/TerminalControl/TermControlAutomationPeer.cpp b/src/cascadia/TerminalControl/TermControlAutomationPeer.cpp index 1f670cd1f6d..41c55b37640 100644 --- a/src/cascadia/TerminalControl/TermControlAutomationPeer.cpp +++ b/src/cascadia/TerminalControl/TermControlAutomationPeer.cpp @@ -112,7 +112,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation { if (const auto keyEventChar{ gsl::narrow_cast(charCode) }; IsReadable({ &keyEventChar, 1 })) { - _keyEvents.emplace_back(keyEventChar); + _keyEvents.lock()->emplace_back(keyEventChar); } } } @@ -202,27 +202,30 @@ namespace winrt::Microsoft::Terminal::Control::implementation void TermControlAutomationPeer::NotifyNewOutput(std::wstring_view newOutput) { - // Try to suppress any events (or event data) - // that is just the keypress the user made auto sanitized{ Sanitize(newOutput) }; - while (!_keyEvents.empty() && IsReadable(sanitized)) + // Try to suppress any events (or event data) + // that are just the keypresses the user made { - if (til::toupper_ascii(sanitized.front()) == _keyEvents.front()) - { - // the key event's character (i.e. the "A" key) matches - // the output character (i.e. "a" or "A" text). - // We can assume that the output character resulted from - // the pressed key, so we can ignore it. - sanitized = sanitized.substr(1); - _keyEvents.pop_front(); - } - else + auto keyEvents = _keyEvents.lock(); + while (!keyEvents->empty() && IsReadable(sanitized)) { - // The output doesn't match, - // so clear the input stack and - // move on to fire the event. - _keyEvents.clear(); - break; + if (til::toupper_ascii(sanitized.front()) == keyEvents->front()) + { + // the key event's character (i.e. the "A" key) matches + // the output character (i.e. "a" or "A" text). + // We can assume that the output character resulted from + // the pressed key, so we can ignore it. + sanitized = sanitized.substr(1); + keyEvents->pop_front(); + } + else + { + // The output doesn't match, + // so clear the input stack and + // move on to fire the event. + keyEvents->clear(); + break; + } } } diff --git a/src/cascadia/TerminalControl/TermControlAutomationPeer.h b/src/cascadia/TerminalControl/TermControlAutomationPeer.h index c9e00340f9c..e8e62cf953c 100644 --- a/src/cascadia/TerminalControl/TermControlAutomationPeer.h +++ b/src/cascadia/TerminalControl/TermControlAutomationPeer.h @@ -80,6 +80,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation private: winrt::weak_ref _termControl; Control::InteractivityAutomationPeer _contentAutomationPeer; - std::deque _keyEvents; + til::shared_mutex> _keyEvents; }; } diff --git a/src/cascadia/TerminalControl/pch.h b/src/cascadia/TerminalControl/pch.h index cbbe86ac0a9..4d1dd8bb85b 100644 --- a/src/cascadia/TerminalControl/pch.h +++ b/src/cascadia/TerminalControl/pch.h @@ -65,6 +65,7 @@ TRACELOGGING_DECLARE_PROVIDER(g_hTerminalControlProvider); #include #include "til.h" +#include #include "ThrottledFunc.h"