Skip to content

Commit

Permalink
Fixes #3518 (#3521)
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft authored and msftbot[bot] committed Nov 13, 2019
1 parent fe4c80b commit 306e751
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
}

_connection.WriteInput(stripped);
_terminal->TrySnapOnInput();
}

// Method Description:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalCore/ITerminalInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
25 changes: 19 additions & 6 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// - <none>
// Return Value:
// - <none>
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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class Microsoft::Terminal::Core::Terminal final :
[[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)
Expand Down

0 comments on commit 306e751

Please sign in to comment.