diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index a75cbee7c..1122dd48d 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -1232,6 +1232,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation } _connection.WriteInput(stripped); + _terminal->TrySnapOnInput(); } // Method Description: diff --git a/src/cascadia/TerminalCore/ITerminalInput.hpp b/src/cascadia/TerminalCore/ITerminalInput.hpp index 880c610c7..ba3804fee 100644 --- a/src/cascadia/TerminalCore/ITerminalInput.hpp +++ b/src/cascadia/TerminalCore/ITerminalInput.hpp @@ -24,6 +24,8 @@ namespace Microsoft::Terminal::Core virtual void UserScrollViewport(const int viewTop) = 0; virtual int GetScrollOffset() = 0; + virtual void TrySnapOnInput() = 0; + protected: ITerminalInput() = default; }; diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 2d7dd5d42..87b05eb88 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -192,6 +192,24 @@ void Terminal::Write(std::wstring_view stringView) _stateMachine->ProcessString(stringView.data(), stringView.size()); } +// Method Description: +// - Attempts to snap to the bottom of the buffer, if SnapOnInput is true. Does +// nothing if SnapOnInput is set to false, or we're already at the bottom of +// the buffer. +// Arguments: +// - +// Return Value: +// - +void Terminal::TrySnapOnInput() +{ + if (_snapOnInput && _scrollOffset != 0) + { + auto lock = LockForWriting(); + _scrollOffset = 0; + _NotifyScrollEvent(); + } +} + // Method Description: // - Send this particular key event to the terminal. The terminal will translate // the key and the modifiers pressed into the appropriate VT sequence for that @@ -207,12 +225,7 @@ void Terminal::Write(std::wstring_view stringView) // - false if we did not translate the key, and it should be processed into a character. bool Terminal::SendKeyEvent(const WORD vkey, const WORD scanCode, const ControlKeyStates states) { - if (_snapOnInput && _scrollOffset != 0) - { - auto lock = LockForWriting(); - _scrollOffset = 0; - _NotifyScrollEvent(); - } + TrySnapOnInput(); // Alt key sequences _require_ the char to be in the keyevent. If alt is // pressed, manually get the character that's being typed, and put it in the diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 56f86c242..d29744a2f 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -92,6 +92,8 @@ public: [[nodiscard]] HRESULT UserResize(const COORD viewportSize) noexcept override; void UserScrollViewport(const int viewTop) override; int GetScrollOffset() override; + + void TrySnapOnInput() override; #pragma endregion #pragma region IBaseData(base to IRenderData and IUiaData)