[PR #9770] [MERGED] Prevent the virtual viewport bottom being moved up unintentionally #27731

Open
opened 2026-01-31 09:23:53 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/9770
Author: @j4james
Created: 4/10/2021
Status: ✅ Merged
Merged: 4/15/2021
Merged by: @undefined

Base: main ← Head: fix-update-bottom


📝 Commits (4)

  • c4b8153 Only move the virtual bottom down, unless it's outside the buffer range.
  • c6897db Reset the virtual bottom when the scrollback is erased.
  • 87e74e4 Make sure the virtual bottom is reset when necessary in ScreenBufferTests.
  • 19f63dc Add unit test to verify the virtual bottom doesn't move up.

📊 Changes

8 files changed (+96 additions, -3 deletions)

View changed files

📝 src/host/outputStream.cpp (+11 -0)
📝 src/host/outputStream.hpp (+1 -0)
📝 src/host/screenInfo.cpp (+21 -3)
📝 src/host/screenInfo.hpp (+1 -0)
📝 src/host/ut_host/ScreenBufferTests.cpp (+53 -0)
📝 src/terminal/adapter/adaptDispatch.cpp (+3 -0)
📝 src/terminal/adapter/conGetSet.hpp (+1 -0)
📝 src/terminal/adapter/ut_adapter/adapterTest.cpp (+5 -0)

📄 Description

Summary of the Pull Request

The "virtual bottom" marks the last line of the mutable viewport area, which is the part of the buffer that VT sequences can write to. This region should typically only move downwards, as new lines are added to the buffer, but there were a number of cases where it was incorrectly being moved up. This PR attempts to fix that.

PR Checklist

  • Closes cursorShape and cursorColor ignored (#9754)
  • CLA signed.
  • Tests added/passed
  • Documentation updated.
  • Schema updated.
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #9754

Detailed Description of the Pull Request / Additional comments

When a call is made to UpdateBottom, we now clamp the value so it's at least as low as the current viewport bottom (i.e. if the viewport has moved down, we want the virtual bottom to move down too), but no lower than the bottom of the buffer (we don't want it to be out of range).

There is one special case where we do actually want the virtual bottom to move up - when the scrollback has been cleared with an ED3 escape sequence. So in that case we needed a new ConGetSet API (ResetBottom) to reset the virtual bottom to the top of the buffer (essentially one less than the viewport height, since the virtual bottom points to the last line of the viewport).

Validation Steps Performed

I had to reset the virtual bottom manually in some parts of the ScreenBufferTests, since some of the tests were relying on the virtual bottom being automatically reset when the viewport was reset, which is no longer the case.

I've also added a new test to verify that the virtual bottom doesn't move upwards if an update is triggered while the visible viewport is scrolled up. This essentially reproduces the test case from issue #9754, which I've also manually confirmed is fixed.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/9770 **Author:** [@j4james](https://github.com/j4james) **Created:** 4/10/2021 **Status:** ✅ Merged **Merged:** 4/15/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `fix-update-bottom` --- ### 📝 Commits (4) - [`c4b8153`](https://github.com/microsoft/terminal/commit/c4b8153a894c6372a6267494f8c9f2df2b1fd8f8) Only move the virtual bottom down, unless it's outside the buffer range. - [`c6897db`](https://github.com/microsoft/terminal/commit/c6897dbab22436fd05f7f26abfa2cc557bb75aea) Reset the virtual bottom when the scrollback is erased. - [`87e74e4`](https://github.com/microsoft/terminal/commit/87e74e431cf5cd0988ecf2d9d77fd125f105bbff) Make sure the virtual bottom is reset when necessary in ScreenBufferTests. - [`19f63dc`](https://github.com/microsoft/terminal/commit/19f63dc6d97eaaaa0a72c771de6bbc8c3f1c2511) Add unit test to verify the virtual bottom doesn't move up. ### 📊 Changes **8 files changed** (+96 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/host/outputStream.cpp` (+11 -0) 📝 `src/host/outputStream.hpp` (+1 -0) 📝 `src/host/screenInfo.cpp` (+21 -3) 📝 `src/host/screenInfo.hpp` (+1 -0) 📝 `src/host/ut_host/ScreenBufferTests.cpp` (+53 -0) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+3 -0) 📝 `src/terminal/adapter/conGetSet.hpp` (+1 -0) 📝 `src/terminal/adapter/ut_adapter/adapterTest.cpp` (+5 -0) </details> ### 📄 Description ## Summary of the Pull Request The "virtual bottom" marks the last line of the mutable viewport area, which is the part of the buffer that VT sequences can write to. This region should typically only move downwards, as new lines are added to the buffer, but there were a number of cases where it was incorrectly being moved up. This PR attempts to fix that. ## PR Checklist * [x] Closes #9754 * [x] CLA signed. * [x] Tests added/passed * [ ] Documentation updated. * [ ] Schema updated. * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #9754 ## Detailed Description of the Pull Request / Additional comments When a call is made to `UpdateBottom`, we now clamp the value so it's at least as low as the current viewport bottom (i.e. if the viewport has moved down, we want the virtual bottom to move down too), but no lower than the bottom of the buffer (we don't want it to be out of range). There is one special case where we do actually want the virtual bottom to move up - when the scrollback has been cleared with an `ED3` escape sequence. So in that case we needed a new `ConGetSet` API (`ResetBottom`) to reset the virtual bottom to the top of the buffer (essentially one less than the viewport height, since the virtual bottom points to the last line of the viewport). ## Validation Steps Performed I had to reset the virtual bottom manually in some parts of the `ScreenBufferTests`, since some of the tests were relying on the virtual bottom being automatically reset when the viewport was reset, which is no longer the case. I've also added a new test to verify that the virtual bottom doesn't move upwards if an update is triggered while the visible viewport is scrolled up. This essentially reproduces the test case from issue #9754, which I've also manually confirmed is fixed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:23:53 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#27731