* Start auto-scrolling in the given direction
(direction: number)
| 689 | * Start auto-scrolling in the given direction |
| 690 | */ |
| 691 | private startAutoScroll(direction: number): void { |
| 692 | // Don't restart if already scrolling in same direction |
| 693 | if (this.autoScrollInterval !== null && this.autoScrollDirection === direction) { |
| 694 | return; |
| 695 | } |
| 696 | |
| 697 | // Stop any existing scroll |
| 698 | this.stopAutoScroll(); |
| 699 | |
| 700 | this.autoScrollDirection = direction; |
| 701 | |
| 702 | // Start scrolling interval |
| 703 | this.autoScrollInterval = setInterval(() => { |
| 704 | if (!this.isSelecting) { |
| 705 | this.stopAutoScroll(); |
| 706 | return; |
| 707 | } |
| 708 | |
| 709 | // Scroll the terminal to reveal more content in the direction user is dragging |
| 710 | // autoScrollDirection: -1 = dragging up (wants to see history), 1 = dragging down (wants to see newer) |
| 711 | // scrollLines convention: negative = scroll up into history, positive = scroll down to newer |
| 712 | // So direction maps directly to scrollLines sign |
| 713 | const scrollAmount = SelectionManager.AUTO_SCROLL_SPEED * this.autoScrollDirection; |
| 714 | (this.terminal as any).scrollLines(scrollAmount); |
| 715 | |
| 716 | // Extend selection in the scroll direction |
| 717 | // Key insight: we need to EXTEND the selection, not reset it to viewport edge |
| 718 | if (this.selectionEnd) { |
| 719 | const dims = this.wasmTerm.getDimensions(); |
| 720 | if (this.autoScrollDirection < 0) { |
| 721 | // Scrolling up - extend selection upward (decrease absoluteRow) |
| 722 | // Set to top of viewport, but only if it extends the selection |
| 723 | const topAbsoluteRow = this.viewportRowToAbsolute(0); |
| 724 | if (topAbsoluteRow < this.selectionEnd.absoluteRow) { |
| 725 | this.selectionEnd = { col: 0, absoluteRow: topAbsoluteRow }; |
| 726 | } |
| 727 | } else { |
| 728 | // Scrolling down - extend selection downward (increase absoluteRow) |
| 729 | // Set to bottom of viewport, but only if it extends the selection |
| 730 | const bottomAbsoluteRow = this.viewportRowToAbsolute(dims.rows - 1); |
| 731 | if (bottomAbsoluteRow > this.selectionEnd.absoluteRow) { |
| 732 | this.selectionEnd = { col: dims.cols - 1, absoluteRow: bottomAbsoluteRow }; |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | this.requestRender(); |
| 738 | }, SelectionManager.AUTO_SCROLL_INTERVAL); |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * Stop auto-scrolling |
no test coverage detected