diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 3870f35cd1c..7ace904e715 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1602,7 +1602,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation } auto lock = _terminal->LockForReading(); - return _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 7482def5e32..ba3a0d84b1f 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -1638,3 +1638,12 @@ til::color Terminal::GetColorForMark(const Microsoft::Console::VirtualTerminal:: } } } + +// Method Description: +// - Returns the position of the cursor relative to the active viewport +til::point Terminal::GetViewportRelativeCursorPosition() const noexcept +{ + const auto absoluteCursorPosition{ GetCursorPosition() }; + const auto viewport{ _GetMutableViewport() }; + return absoluteCursorPosition - viewport.Origin(); +} diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 5dec2e85124..ee898b720eb 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);