Repository: microsoft/terminal
File: src/terminal/adapter/adaptDispatch.cpp (C++)

Code before:
// Arguments:
// - <none>
// Return Value:
// - True.
bool AdaptDispatch::CursorRestoreState()
{
    auto& savedCursorState = _savedCursorState.at(_usingAltBuffer);

    auto row = savedCursorState.Row;
    const auto col = savedCursorState.Column;

    // If the origin mode is relative, we need to make sure the restored
    // position is clamped within the margins.
    if (savedCursorState.IsOriginModeRelative)
    {
        const auto viewport = _api.GetViewport();
        const auto [topMargin, bottomMargin] = _GetVerticalMargins(viewport, false);
        // VT origin is at 1,1 so we need to add 1 to these margins.
        row = std::clamp(row, topMargin + 1, bottomMargin + 1);
    }

    // The saved coordinates are always absolute, so we need reset the origin mode temporarily.
    _modes.reset(Mode::Origin);
    CursorPosition(row, col);

    // If the delayed wrap flag was set when the cursor was saved, we need to restore than now.
    if (savedCursorState.IsDelayedEOLWrap)
    {
        _api.GetTextBuffer().GetCursor().DelayEOLWrap();
    }

    // Once the cursor position is restored, we can then restore the actual origin mode.
    _modes.set(Mode::Origin, savedCursorState.IsOriginModeRelative);

    // Restore text attributes.
    _api.SetTextAttributes(savedCursorState.Attributes);

    // Restore designated character set.
    _termOutput = savedCursorState.TermOutput;

    // Restore the parsing state of C1 control codes.
    AcceptC1Controls(savedCursorState.C1ControlsAccepted);

    // Restore the code page if it was previously saved.
    if (savedCursorState.CodePage != 0)
    {
        _api.SetConsoleOutputCP(savedCursorState.CodePage);
    }

    return true;
}

Review comment (suggestion):
```suggestion
    // If the delayed wrap flag was set when the cursor was saved, we need to restore that now.
```

Code after:
// Arguments:
// - <none>
// Return Value:
// - True.
bool AdaptDispatch::CursorRestoreState()
{
    auto& savedCursorState = _savedCursorState.at(_usingAltBuffer);

    auto row = savedCursorState.Row;
    const auto col = savedCursorState.Column;

    // If the origin mode is relative, we need to make sure the restored
    // position is clamped within the margins.
    if (savedCursorState.IsOriginModeRelative)
    {
        const auto viewport = _api.GetViewport();
        const auto [topMargin, bottomMargin] = _GetVerticalMargins(viewport, false);
        // VT origin is at 1,1 so we need to add 1 to these margins.
        row = std::clamp(row, topMargin + 1, bottomMargin + 1);
    }

    // The saved coordinates are always absolute, so we need reset the origin mode temporarily.
    _modes.reset(Mode::Origin);
    CursorPosition(row, col);

    // If the delayed wrap flag was set when the cursor was saved, we need to restore that now.
    if (savedCursorState.IsDelayedEOLWrap)
    {
        _api.GetTextBuffer().GetCursor().DelayEOLWrap();
    }

    // Once the cursor position is restored, we can then restore the actual origin mode.
    _modes.set(Mode::Origin, savedCursorState.IsOriginModeRelative);

    // Restore text attributes.
    _api.SetTextAttributes(savedCursorState.Attributes);

    // Restore designated character set.
    _termOutput = savedCursorState.TermOutput;

    // Restore the parsing state of C1 control codes.
    AcceptC1Controls(savedCursorState.C1ControlsAccepted);

    // Restore the code page if it was previously saved.
    if (savedCursorState.CodePage != 0)
    {
        _api.SetConsoleOutputCP(savedCursorState.CodePage);
    }

    return true;
}