[PR #1807] [MERGED] Fix margin boundary tests in the RI, DL, and IL escape sequences. #24666

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/1807
Author: @j4james
Created: 7/3/2019
Status: Merged
Merged: 7/10/2019
Merged by: @miniksa

Base: masterHead: fix-margin-scrolling


📝 Commits (3)

  • 56a1dbf Fix margin boundary tests in the RI, DL, and IL sequences.
  • f2ae9c9 Refactor the margin boundary tests into a reusable SCREEN_INFORMATION method.
  • 8b9acbf Add screen buffer unit tests for the RI, DL, and IL sequences.

📊 Changes

4 files changed (+252 additions, -11 deletions)

View changed files

📝 src/host/getset.cpp (+4 -11)
📝 src/host/screenInfo.cpp (+18 -0)
📝 src/host/screenInfo.hpp (+1 -0)
📝 src/host/ut_host/ScreenBufferTests.cpp (+229 -0)

📄 Description

Summary of the Pull Request

When executing an escape sequence that might cause the viewport to scroll, a check is made to see whether the cursor position is in the bounds of the scroll margins, otherwise the scroll operation shouldn't happen. In a couple of cases (in the RI, DL, and IL escape sequence), these boundary tests were incorrect, so the scroll operation would sometimes not occur when it should have. This PR fixes those boundary tests.

Tested manually, and with the joe editor which was previously failing, and with some additional screen buffer unit tests.

PR Checklist

  • Closes Bug Report: Reaction to Keyboard input is anomalous (#1366)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be 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: #1366

Detailed Description of the Pull Request / Additional comments

The one problem was the use of Viewport::IsInBounds method to check whether the cursor was inside the margins. That method only works on the first column of the screen, because the horizontal margins are always set to 0. So that needed to be replaced with a test that only checked the y offset against the vertical margins.

The other problem was not first checking whether the margins had actually been set. When the margins aren't set, the top and bottom boundaries are both 0, so that needs to be handled as a special case, otherwise it'll only match positions on the first line of the screen.

Having made these fixes in the DoSrvPrivateReverseLineFeed and DoSrvPrivateModifyLinesImpl methods, I thought it might also be a good idea to refactor the boundary tests into a shared method in the SCREEN_INFORMATION class, to try and make the code more readable. I could also then make use of that method to simplify the DoSrvMoveCursorVertically implementation a little.

I had initially planned to refactor the AdjustCursorPosition method as well, but I decided against that in the end, because the code is a lot more complicated in that case, and I didn't want to risk potential performance issues given the frequency of its use.

In any event, I've committed the refactoring as a separate step, so I can always revert that if you don't think it's a good idea.

Validation Steps Performed

I've added a few screen buffer units tests that make sure the RI, DL, and IL escape sequences basically work, and also specifically check the conditions that were previously failing.

I've also run a few of my own manual tests which check various margin boundary conditions. And I've made sure that the problem with joe editor that was reported in issue #1366 is now working.


🔄 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/1807 **Author:** [@j4james](https://github.com/j4james) **Created:** 7/3/2019 **Status:** ✅ Merged **Merged:** 7/10/2019 **Merged by:** [@miniksa](https://github.com/miniksa) **Base:** `master` ← **Head:** `fix-margin-scrolling` --- ### 📝 Commits (3) - [`56a1dbf`](https://github.com/microsoft/terminal/commit/56a1dbf702b55ed679642806e7d8181f5700d815) Fix margin boundary tests in the RI, DL, and IL sequences. - [`f2ae9c9`](https://github.com/microsoft/terminal/commit/f2ae9c9a9179c083bb0ddf06fdb82958ddfefc4f) Refactor the margin boundary tests into a reusable SCREEN_INFORMATION method. - [`8b9acbf`](https://github.com/microsoft/terminal/commit/8b9acbfe840db27d0dc2ee7088f6f30db080d527) Add screen buffer unit tests for the RI, DL, and IL sequences. ### 📊 Changes **4 files changed** (+252 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `src/host/getset.cpp` (+4 -11) 📝 `src/host/screenInfo.cpp` (+18 -0) 📝 `src/host/screenInfo.hpp` (+1 -0) 📝 `src/host/ut_host/ScreenBufferTests.cpp` (+229 -0) </details> ### 📄 Description <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request When executing an escape sequence that might cause the viewport to scroll, a check is made to see whether the cursor position is in the bounds of the scroll margins, otherwise the scroll operation shouldn't happen. In a couple of cases (in the RI, DL, and IL escape sequence), these boundary tests were incorrect, so the scroll operation would sometimes not occur when it should have. This PR fixes those boundary tests. Tested manually, and with the _joe_ editor which was previously failing, and with some additional screen buffer unit tests. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #1366 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [ ] Requires documentation to be 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: #1366 <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments The one problem was the use of `Viewport::IsInBounds` method to check whether the cursor was inside the margins. That method only works on the first column of the screen, because the horizontal margins are always set to 0. So that needed to be replaced with a test that only checked the y offset against the vertical margins. The other problem was not first checking whether the margins had actually been set. When the margins aren't set, the top and bottom boundaries are both 0, so that needs to be handled as a special case, otherwise it'll only match positions on the first line of the screen. Having made these fixes in the `DoSrvPrivateReverseLineFeed` and `DoSrvPrivateModifyLinesImpl` methods, I thought it might also be a good idea to refactor the boundary tests into a shared method in the `SCREEN_INFORMATION` class, to try and make the code more readable. I could also then make use of that method to simplify the `DoSrvMoveCursorVertically` implementation a little. I had initially planned to refactor the `AdjustCursorPosition` method as well, but I decided against that in the end, because the code is a lot more complicated in that case, and I didn't want to risk potential performance issues given the frequency of its use. In any event, I've committed the refactoring as a separate step, so I can always revert that if you don't think it's a good idea. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed I've added a few screen buffer units tests that make sure the RI, DL, and IL escape sequences basically work, and also specifically check the conditions that were previously failing. I've also run a few of my own manual tests which check various margin boundary conditions. And I've made sure that the problem with _joe_ editor that was reported in issue #1366 is now working. --- <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:04:40 +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#24666