feat: Improve selection handling for buffer trims and scrolling#4
Merged
Conversation
- Add Trimmed event to TerminalBuffer for line trimming notifications - Update SelectionManager to track and adjust selection on trims - Refactor selection logic to use absolute buffer coordinates - Ensure SelectAll covers full buffer, not just viewport - Enhance GetSelectionText and IsCellSelected for accuracy - Add tests for selection anchoring, scrolling, and trim behavior
tomlm
approved these changes
May 13, 2026
Owner
|
Thanks! |
Owner
|
I pushed a new package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Update selection handling in
XTerm.NETto better matchxterm.js.This changes selection from a viewport-relative model to a buffer-anchored model so selection stays attached to the underlying buffer content when the viewport scrolls.
What changed
SelectionManagerStartSelectionUpdateSelectionIsCellSelectedGetSelectionText()to read directly from absolute buffer lines instead ofbuffer.YDisp + rowSelectAll()to cover the full buffer, including scrollback, not just the visible viewportTerminalBuffer.Trimmedso selection can respond when buffer lines are droppedWhy
The previous selection implementation was tied to viewport rows:
xterm.jsbehaves differently. Its selection model is buffer-oriented and adjusts selection when scrollback is trimmed. This change movesXTerm.NETcloser to that behavior.Tests
Added focused tests covering:
IsCellSelectedfollows the selected buffer line across viewport movementSelectAllincludes scrollback, not just the visible rowsValidation:
dotnet test src/XTerm.NET.Tests/XTerm.NET.Tests.csproj584/584