diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 218146b9ea3..1c832194c49 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1419,7 +1419,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation } auto lock = _terminal->LockForReading(); - return til::point{ _terminal->GetCursorPosition() }.to_core_point(); + return _terminal->GetViewportRelativeCursorPosition().to_core_point(); } // This one's really pushing the boundary of what counts as "encapsulation". diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 66b3e77bca5..bb8ba14161b 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -1462,3 +1462,12 @@ void Terminal::_updateUrlDetection() ClearPatternTree(); } } + +// Method Description: +// - Returns the position of the cursor relative to the active viewport +til::point Terminal::GetViewportRelativeCursorPosition() const noexcept +{ + const til::point absoluteCursorPosition{ GetCursorPosition() }; + const auto viewport{ _GetMutableViewport() }; + return absoluteCursorPosition - til::point{ viewport.Origin() }; +} diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index b88f79b653c..4db779ae1b9 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -84,6 +84,8 @@ class Microsoft::Terminal::Core::Terminal final : bool IsXtermBracketedPasteModeEnabled() const; std::wstring_view GetWorkingDirectory(); + til::point GetViewportRelativeCursorPosition() const noexcept; + // Write comes from the PTY and goes to our parser to be stored in the output buffer void Write(std::wstring_view stringView);