The best way to control Claude Code, Codex and more from any computer or phone
fix(web): terminal drag selection scrolls faster the farther past the edge (#22872)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 25, 2026 at 15:09 UTC
313ca2715fbef89e3ed7395a3d146661e2223fd9
2 files changed
+32
-1
apps/web/src/terminal/ghostty/surface.test.ts
+16
@@ -11,6 +11,7 @@ import {
11
resolveTerminalMouseData,
12
terminalLinkAtPositionWithRange,
13
terminalContentOriginY,
14
+ terminalSelectionAutoscrollRows,
15
terminalWheelDeltaRows,
16
GhosttyTerminalSurface,
17
type GhosttyTerminalSurfaceOptions,
@@ -747,6 +748,21 @@ describe("terminalWheelDeltaRows", () => {
748
});
749
});
750
751
+// regression: #19492 drag selection scrolled one row per tick however far past the edge
752
+describe("terminalSelectionAutoscrollRows", () => {
753
+ it("scrolls more rows per tick the farther the pointer is past an edge", () => {
754
+ const top = 100;
755
+ const bottom = 500;
756
+ expect(terminalSelectionAutoscrollRows(300, top, bottom)).toBe(0);
757
+ expect(terminalSelectionAutoscrollRows(99, top, bottom)).toBe(-1);
758
+ expect(terminalSelectionAutoscrollRows(75, top, bottom)).toBe(-8);
759
+ expect(terminalSelectionAutoscrollRows(501, top, bottom)).toBe(1);
760
+ expect(terminalSelectionAutoscrollRows(525, top, bottom)).toBe(8);
761
+ expect(terminalSelectionAutoscrollRows(550, top, bottom)).toBe(15);
762
+ expect(terminalSelectionAutoscrollRows(2_000, top, bottom)).toBe(15);
763
+ });
764
+});
765
+
766
describe("advanceTerminalSelectionClickSequence", () => {
767
it("recognizes stationary double and triple pointer presses without PointerEvent.detail", () => {
768
const first = advanceTerminalSelectionClickSequence(null, {
apps/web/src/terminal/ghostty/surface.ts
+16
-1
@@ -423,6 +423,21 @@ export function terminalWheelDeltaRows(
423
return { rows, remainder: total - rows };
424
}
425
426
+// Ramp from 1 to 15 rows per autoscroll tick over the first 50px past the edge, as xterm.js does.
427
+const SELECTION_AUTOSCROLL_RAMP_PX = 50;
428
+const SELECTION_AUTOSCROLL_MAX_ROWS = 15;
429
+
430
+export function terminalSelectionAutoscrollRows(
431
+ clientY: number,
432
+ top: number,
433
+ bottom: number,
434
+): number {
435
+ const distance = clientY < top ? clientY - top : clientY > bottom ? clientY - bottom : 0;
436
+ if (distance === 0) return 0;
437
+ const ramp = Math.max(-1, Math.min(1, distance / SELECTION_AUTOSCROLL_RAMP_PX));
438
+ return Math.sign(ramp) + Math.round(ramp * (SELECTION_AUTOSCROLL_MAX_ROWS - 1));
439
+}
440
+
441
function terminalWheelArrowData(rows: number, applicationCursorKeys: boolean): string {
442
if (rows === 0) return "";
443
const sequence =
@@ -1434,7 +1449,7 @@ export class GhosttyTerminalSurface {
1449
const bounds = this.canvas.getBoundingClientRect();
1450
const top = Math.max(bounds.top, 0) + CONTENT_PADDING;
1451
const bottom = Math.min(bounds.bottom, window.innerHeight) - CONTENT_PADDING;
1437
- this.setSelectionAutoscroll(event.clientY < top ? -1 : event.clientY > bottom ? 1 : 0);
1452
+ this.setSelectionAutoscroll(terminalSelectionAutoscrollRows(event.clientY, top, bottom));
1453
const cell = this.cellAt(event.clientX, event.clientY);
1454
if (cell.x === this.selectionEnd?.x && cell.y === this.selectionEnd.y) return;
1455
this.extendSelectionTo(event.clientX, event.clientY);