[PR #19603] Fix dangling search selection using viewport pos #31889

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

Original Pull Request: https://github.com/microsoft/terminal/pull/19603

State: closed
Merged: Yes


Summary of the Pull Request

Fixes a bug where the dangling selection from a search would be applied to the wrong position. Specifically, the issue is that SetSelectionAnchor() and SetSelectionEnd() expect viewport positions whereas the searcher outputs buffer positions.

This PR simply applies the scroll offset to the search result before calling the functions.

In a separate iteration, I changed the functions to allow for viewport-relative vs buffer-relative positions. However, that ended up feeling a bit odd because this is the only scenario where the functions were receiving buffer-relative positions. I chose this approach instead because it's smaller/cleaner, even though we convert to viewport-relative before the call just to change it to buffer-relative in the function.

Bug introduced in #19550

Validation Steps Performed

The correct region is selected in the following scenarios:
no scrollback
with scrollback, at bottom
with scrollback, not at bottom (selection isn't scrolled to, but I think that's ok. Can be fixed easily if requested)
alt buffer

**Original Pull Request:** https://github.com/microsoft/terminal/pull/19603 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request Fixes a bug where the dangling selection from a search would be applied to the wrong position. Specifically, the issue is that `SetSelectionAnchor()` and `SetSelectionEnd()` expect viewport positions whereas the searcher outputs buffer positions. This PR simply applies the scroll offset to the search result before calling the functions. In a separate iteration, I changed the functions to allow for viewport-relative vs buffer-relative positions. However, that ended up feeling a bit odd because this is the only scenario where the functions were receiving buffer-relative positions. I chose this approach instead because it's smaller/cleaner, even though we convert to viewport-relative before the call just to change it to buffer-relative in the function. Bug introduced in #19550 ## Validation Steps Performed The correct region is selected in the following scenarios: ✅ no scrollback ✅ with scrollback, at bottom ✅ with scrollback, not at bottom (selection isn't scrolled to, but I think that's ok. Can be fixed easily if requested) ✅ alt buffer
claunia added the pull-request label 2026-01-31 09:50:12 +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#31889