From 2c7c4ecbec2bf880b18a85589312f75c63598a66 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Thu, 4 Dec 2025 04:02:52 -0600 Subject: [PATCH] fix: correct selection overflow during auto-scroll The auto-scroll selection handler was using viewportY directly as the absolute row position, but the coordinate systems are different: - viewportY = how far scrolled into history (0 = at bottom) - absoluteRow = index into combined buffer (0 = oldest scrollback) This caused selections to jump to very old scrollback lines when auto-scrolling upward. Fixed by using viewportRowToAbsolute() helper which correctly converts viewport coordinates to absolute buffer rows. --- lib/selection-manager.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/selection-manager.ts b/lib/selection-manager.ts index 5b2af73..9182fe5 100644 --- a/lib/selection-manager.ts +++ b/lib/selection-manager.ts @@ -705,20 +705,19 @@ export class SelectionManager { // Key insight: we need to EXTEND the selection, not reset it to viewport edge if (this.selectionEnd) { const dims = this.wasmTerm.getDimensions(); - const viewportY = this.getViewportY(); if (this.autoScrollDirection < 0) { // Scrolling up - extend selection upward (decrease absoluteRow) // Set to top of viewport, but only if it extends the selection - const topOfViewport = viewportY; - if (topOfViewport < this.selectionEnd.absoluteRow) { - this.selectionEnd = { col: 0, absoluteRow: topOfViewport }; + const topAbsoluteRow = this.viewportRowToAbsolute(0); + if (topAbsoluteRow < this.selectionEnd.absoluteRow) { + this.selectionEnd = { col: 0, absoluteRow: topAbsoluteRow }; } } else { // Scrolling down - extend selection downward (increase absoluteRow) // Set to bottom of viewport, but only if it extends the selection - const bottomOfViewport = viewportY + dims.rows - 1; - if (bottomOfViewport > this.selectionEnd.absoluteRow) { - this.selectionEnd = { col: dims.cols - 1, absoluteRow: bottomOfViewport }; + const bottomAbsoluteRow = this.viewportRowToAbsolute(dims.rows - 1); + if (bottomAbsoluteRow > this.selectionEnd.absoluteRow) { + this.selectionEnd = { col: dims.cols - 1, absoluteRow: bottomAbsoluteRow }; } } }