[PR #3704] [MERGED] Don't allow a linefeed to scroll when outside DECSTBM margins #25482

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/3704
Author: @j4james
Created: 11/26/2019
Status: ✅ Merged
Merged: 12/11/2019
Merged by: @undefined

Base: master ← Head: fix-lf-outside-margins


📝 Commits (2)

  • 824ccde Don't allow a linefeed to scroll the screen when outside the DECSTBM margins.
  • 0363aff Add screen buffer test to check the behaviour of linefeeds outside margins.

📊 Changes

2 files changed (+41 additions, -0 deletions)

View changed files

📝 src/host/_stream.cpp (+9 -0)
📝 src/host/ut_host/ScreenBufferTests.cpp (+32 -0)

📄 Description

Summary of the Pull Request

When the DECSTBM margins are set, scrolling should only allowed within
those margins. So if the cursor is below the bottom margin, it should
just be clamped when it tries to move down from the bottom line of the
viewport, instead of scrolling the screen up. This PR implements that
restriction, i.e. it prevents scrolling taking place outside the
DECSTBM margins, which was previously allowed.

PR Checklist

Detailed Description of the Pull Request / Additional comments

This simply adds a condition in the AdjustCursorPosition function to
check if the cursor is moving below the bottom of the viewport when the
margins are set. If so, it clamps the y coordinate to the bottom line of
the viewport.

The only time it's acceptable for scrolling to happen when margins are
set, is if the scrolling is taking place within those margins. But those
cases would already have been handled earlier in the function (in the
fScrollDown or scrollDownAtTop conditions), and thus the y
coordinate would have already been prevented from moving out of the
viewport.

Validation Steps Performed

I've added some screen buffer tests to confirm this new behaviour, and
I've also checked the test case from the initial bug report (#2657) and
made sure it now matches the results in XTerm.


🔄 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/3704 **Author:** [@j4james](https://github.com/j4james) **Created:** 11/26/2019 **Status:** ✅ Merged **Merged:** 12/11/2019 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `fix-lf-outside-margins` --- ### 📝 Commits (2) - [`824ccde`](https://github.com/microsoft/terminal/commit/824ccde36d831db63fe07c1cd0e7a6ce6c86f0c0) Don't allow a linefeed to scroll the screen when outside the DECSTBM margins. - [`0363aff`](https://github.com/microsoft/terminal/commit/0363affe4b9cd1371e57f1b29f1738ca719a511c) Add screen buffer test to check the behaviour of linefeeds outside margins. ### 📊 Changes **2 files changed** (+41 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/host/_stream.cpp` (+9 -0) 📝 `src/host/ut_host/ScreenBufferTests.cpp` (+32 -0) </details> ### 📄 Description ## Summary of the Pull Request When the `DECSTBM` margins are set, scrolling should only allowed within those margins. So if the cursor is below the bottom margin, it should just be clamped when it tries to move down from the bottom line of the viewport, instead of scrolling the screen up. This PR implements that restriction, i.e. it prevents scrolling taking place outside the `DECSTBM` margins, which was previously allowed. ## PR Checklist * [x] Closes #2657 * [x] CLA signed. * [x] Tests added/passed ## Detailed Description of the Pull Request / Additional comments This simply adds a condition in the `AdjustCursorPosition` function to check if the cursor is moving below the bottom of the viewport when the margins are set. If so, it clamps the y coordinate to the bottom line of the viewport. The only time it's acceptable for scrolling to happen when margins are set, is if the scrolling is taking place within those margins. But those cases would already have been handled earlier in the function (in the `fScrollDown` or `scrollDownAtTop` conditions), and thus the y coordinate would have already been prevented from moving out of the viewport. ## Validation Steps Performed I've added some screen buffer tests to confirm this new behaviour, and I've also checked the test case from the initial bug report (#2657) and made sure it now matches the results in XTerm. --- <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:09:47 +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#25482