Skip to content

Commit

Permalink
Update DECSC and CPR commands to account for the column offset being …
Browse files Browse the repository at this point in the history
…relative to the buffer and not the viewport.
  • Loading branch information
j4james committed Dec 22, 2019
1 parent 4a9c6dd commit 9cf7a9b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,14 @@ bool AdaptDispatch::CursorSaveState()
if (success)
{
// The cursor is given to us by the API as relative to the whole buffer.
// But in VT speak, the cursor should be relative to the current viewport. Adjust.
COORD const coordCursor = csbiex.dwCursorPosition;

SMALL_RECT const srViewport = csbiex.srWindow;
// But in VT speak, the cursor row should be relative to the current viewport top.
COORD coordCursor = csbiex.dwCursorPosition;
coordCursor.Y -= csbiex.srWindow.Top;

// VT is also 1 based, not 0 based, so correct by 1.
auto& savedCursorState = _savedCursorState.at(_usingAltBuffer);
savedCursorState.Column = coordCursor.X - srViewport.Left + 1;
savedCursorState.Row = coordCursor.Y - srViewport.Top + 1;
savedCursorState.Column = coordCursor.X + 1;
savedCursorState.Row = coordCursor.Y + 1;
savedCursorState.IsOriginModeRelative = _isOriginModeRelative;
savedCursorState.Attributes = attributes;
savedCursorState.TermOutput = _termOutput;
Expand Down Expand Up @@ -695,8 +694,7 @@ bool AdaptDispatch::_CursorPositionReport() const
// First pull the cursor position relative to the entire buffer out of the console.
COORD coordCursorPos = csbiex.dwCursorPosition;

// Now adjust it for its position in respect to the current viewport.
coordCursorPos.X -= csbiex.srWindow.Left;
// Now adjust it for its position in respect to the current viewport top.
coordCursorPos.Y -= csbiex.srWindow.Top;

// NOTE: 1,1 is the top-left corner of the viewport in VT-speak, so add 1.
Expand Down

0 comments on commit 9cf7a9b

Please sign in to comment.