Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset _wrapForced when erasing scrollback #16610

Merged
merged 2 commits into from
Jan 29, 2024
Merged

Reset _wrapForced when erasing scrollback #16610

merged 2 commits into from
Jan 29, 2024

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Jan 27, 2024

#15541 changed AdaptDispatch::_FillRect which caused it to not affect
the ROW::_wrapForced flag anymore. This change in behavior was not
noticeable as TextBuffer::GetLastNonSpaceCharacter had a bug where
rows of only whitespace text would always be treated as empty.
This would then affect AdaptDispatch::_EraseAll to accidentally
correctly guess the last row with text despite the _FillRect change.

#15701 then fixed GetLastNonSpaceCharacter indirectly by fixing
ROW::MeasureRight which now made the previous change apparent.
_EraseAll would now guess the last row of text incorrectly,
because it would find the rows that _FillRect cleared but still
had _wrapForced set to true.

This PR fixes the issue by replacing the _FillRect usage to clear
rows with direct calls to ROW::Reset(). In the future this could be
extended by also MEM_DECOMMITing the now unused underlying memory.

Closes #16603

Validation Steps Performed

  • Enter WSL and resize the window to <40 columns
  • Execute
    cd /bin
    ls -la
    printf "\e[3J"
    ls -la
    printf "\e[3J"
    printf "\e[2J"
  • Only one viewport-height-many lines of whitespace exist between the
    current prompt line and the previous scrollback contents ✅

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-VT Virtual Terminal sequence support Product-Conhost For issues in the Console codebase labels Jan 27, 2024
@DHowett
Copy link
Member

DHowett commented Jan 29, 2024

(FWIW, the class name is "Adapt"Dispatch :))

@lhecker lhecker marked this pull request as ready for review January 29, 2024 15:53
@DHowett DHowett added this to To Cherry Pick in 1.19 Servicing Pipeline via automation Jan 29, 2024
// The start parameter is relative to the _firstRow. The trick to get the content to the absolute start
// is to simply add _firstRow ourselves and then reset it to 0. This causes ScrollRows() to write into
// the absolute start while reading from relative coordinates. This works because GetRowByOffset()
// operates modulo the buffer height and so the possibly-too-large startAbsolute won't be an issue.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is horrifying

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... Alternative approaches aren't particularly nice either unfortunately, hence the big comment. But I believe this will remain the only function that would need such a trick, so the impact is at least limited. 😅

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I think I follow. Kinda surprised that a test didn't catch this?

@DHowett DHowett merged commit 5f71cf3 into main Jan 29, 2024
20 checks passed
@DHowett DHowett deleted the dev/lhecker/16603-ed2 branch January 29, 2024 22:49
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.19 Servicing Pipeline Jan 29, 2024
DHowett pushed a commit that referenced this pull request Jan 29, 2024
#15541 changed `AdaptDispatch::_FillRect` which caused it to not affect
the `ROW::_wrapForced` flag anymore. This change in behavior was not
noticeable as `TextBuffer::GetLastNonSpaceCharacter` had a bug where
rows of only whitespace text would always be treated as empty.
This would then affect `AdaptDispatch::_EraseAll` to accidentally
correctly guess the last row with text despite the `_FillRect` change.

#15701 then fixed `GetLastNonSpaceCharacter` indirectly by fixing
`ROW::MeasureRight` which now made the previous change apparent.
`_EraseAll` would now guess the last row of text incorrectly,
because it would find the rows that `_FillRect` cleared but still
had `_wrapForced` set to `true`.

This PR fixes the issue by replacing the `_FillRect` usage to clear
rows with direct calls to `ROW::Reset()`. In the future this could be
extended by also `MEM_DECOMMIT`ing the now unused underlying memory.

Closes #16603

## Validation Steps Performed
* Enter WSL and resize the window to <40 columns
* Execute
  ```sh
  cd /bin
  ls -la
  printf "\e[3J"
  ls -la
  printf "\e[3J"
  printf "\e[2J"
  ```
* Only one viewport-height-many lines of whitespace exist between the
  current prompt line and the previous scrollback contents ✅

(cherry picked from commit 5f71cf3)
Service-Card-Id: 91707937
Service-Version: 1.19
@DHowett DHowett moved this from Cherry Picked to Shipped in 1.19 Servicing Pipeline Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Conhost For issues in the Console codebase
Projects
Development

Successfully merging this pull request may close these issues.

ED2 inserts loads of blank lines in scrollback
4 participants