[PR #1317] [MERGED] Bugfix: vertical selection out of bounds #24579

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/1317
Author: @carlos-zamora
Created: 6/19/2019
Status: Merged
Merged: 6/19/2019
Merged by: @DHowett-MSFT

Base: masterHead: dev/cazamor/bugfix-selection-crash-top


📝 Commits (5)

  • aa6c554 Fix crash bug and acknowledge that getting cell data can cause a crash
  • 0492a7e minor comment fix
  • 84d3621 borrowed code from dev/duhowett/the_clamps
  • fa2b239 code format
  • 6408e9b Revert "minor comment fix"

📊 Changes

2 files changed (+18 additions, -14 deletions)

View changed files

📝 src/cascadia/TerminalCore/Terminal.hpp (+2 -2)
📝 src/cascadia/TerminalCore/TerminalSelection.cpp (+16 -12)

📄 Description

Summary of the Pull Request

This was a side effect of #905. But applies the same logic #1254. We were trying to get buffer data at a location that doesn't exist for the buffer. Removed the noexcepts from the expand selection functions.

The fix is simple enough. Just clamp the Y value of the selection to be between 0 and the mutable viewport's height. I tried using the Viewport's Clamp method but we're doing some weird transforms so I found that it's just easiest to do it manually (and slightly differently).

As an extra benefit, now if you're all the way at the top of the buffer and you try making a selection past the top, the x-value still updates as you move. The same thing applies to the bottom when you're at the bottom of the buffer.

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

  • create a selection expanding past the top of the window
  • do same selection as above but right-click to copy (this tests extracting the data from the buffer is still done properly)
  • do both tests above, but for the bottom (this wasn't an issue before, and shouldn't be one now)
  • repeat mentioned tests when you create a scrollable region and you are NOT at the boundaries

NOTE: for that last one, the selection should actually expand to outside of the viewport. That's actually intended as we need that for #1247 .


🔄 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/1317 **Author:** [@carlos-zamora](https://github.com/carlos-zamora) **Created:** 6/19/2019 **Status:** ✅ Merged **Merged:** 6/19/2019 **Merged by:** [@DHowett-MSFT](https://github.com/DHowett-MSFT) **Base:** `master` ← **Head:** `dev/cazamor/bugfix-selection-crash-top` --- ### 📝 Commits (5) - [`aa6c554`](https://github.com/microsoft/terminal/commit/aa6c554635bcf9858b9cf6d8642478a60b4206d1) Fix crash bug and acknowledge that getting cell data can cause a crash - [`0492a7e`](https://github.com/microsoft/terminal/commit/0492a7e967ae4611ba94fc9deed6faf7a244c645) minor comment fix - [`84d3621`](https://github.com/microsoft/terminal/commit/84d362163171bfa2d4e833faf9138ec7e2838a1a) borrowed code from dev/duhowett/the_clamps - [`fa2b239`](https://github.com/microsoft/terminal/commit/fa2b2396c998b4a33e0219172d4901a899d624f8) code format - [`6408e9b`](https://github.com/microsoft/terminal/commit/6408e9b06b1d10f0b6614db1b868060b7294a00f) Revert "minor comment fix" ### 📊 Changes **2 files changed** (+18 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalCore/Terminal.hpp` (+2 -2) 📝 `src/cascadia/TerminalCore/TerminalSelection.cpp` (+16 -12) </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 This was a side effect of #905. But applies the same logic #1254. We were trying to get buffer data at a location that doesn't exist for the buffer. Removed the `noexcept`s from the expand selection functions. The fix is simple enough. Just clamp the Y value of the selection to be between 0 and the mutable viewport's height. I tried using the Viewport's Clamp method but we're doing some weird transforms so I found that it's just easiest to do it manually (and slightly differently). As an extra benefit, now if you're all the way at the top of the buffer and you try making a selection past the top, the x-value still updates as you move. The same thing applies to the bottom when you're at the bottom of the buffer. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #1312 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] 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. <!-- 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 <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed - create a selection expanding past the top of the window - do same selection as above but right-click to copy (this tests extracting the data from the buffer is still done properly) - do both tests above, but for the bottom (this wasn't an issue before, and shouldn't be one now) - repeat mentioned tests when you create a scrollable region and you are NOT at the boundaries NOTE: for that last one, the selection should actually expand to outside of the viewport. That's actually intended as we need that for #1247 . --- <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:09 +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#24579