Skip to content

Clamp selection text bounds#9

Open
jchristn wants to merge 2 commits into
tomlm:mainfrom
jchristn:fix/selection-bounds
Open

Clamp selection text bounds#9
jchristn wants to merge 2 commits into
tomlm:mainfrom
jchristn:fix/selection-bounds

Conversation

@jchristn

@jchristn jchristn commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

This prevents SelectionManager.GetSelectionText() from passing out-of-range columns into BufferLine.TranslateToString().

Selection coordinates can come from pointer positions outside the terminal cell grid, for example dragging slightly left of the terminal before copying. A negative start column can currently produce an IndexOutOfRangeException while translating the selected line.

The fix clamps start and end columns to the valid terminal column range before translating each selected line.

Validation

  • dotnet test src\XTerm.NET.slnx
    • 586 passed, 0 failed

@jchristn jchristn marked this pull request as ready for review June 1, 2026 23:18
@tomlm tomlm requested a review from Copilot June 21, 2026 04:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens SelectionManager.GetSelectionText() against selection coordinates that fall outside the terminal’s column bounds (e.g., pointer drags slightly outside the cell grid), preventing BufferLine.TranslateToString() from being called with negative start indices.

Changes:

  • Clamp per-line selection start/end columns to [0, Cols - 1] before translating selected buffer lines.
  • Skip translating a line when clamped bounds would be invalid (startX > endX).
  • Add unit tests covering negative start columns and columns past the right edge.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/XTerm.NET/Selection/SelectionManager.cs Clamps selection X bounds before translating selection text to avoid out-of-range indices.
src/XTerm.NET.Tests/SelectionTests.cs Adds tests intended to validate clamping behavior for selection text extraction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/XTerm.NET/Selection/SelectionManager.cs Outdated
@tomlm

tomlm commented Jun 21, 2026

Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants