@devries-cameron20 / t3code Mirror · read-only / commits / 5cbdf00481
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 17:15 UTC

fix(web): mostly vertical trackpad scrolls no longer navigate back or forward (#30173)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 13, 2026 at 09:07 UTC 5cbdf00481bc79c16c38337a727507477dbd6e3f
2 files changed +55 -1
apps/web/src/components/HistorySwipeNavigation.browser.test.tsx
+32
@@ -71,4 +71,36 @@ describe("HistorySwipeNavigation", () => {
71
72 expect(navigateHistory).not.toHaveBeenCalled();
73 });
74 +
75 + // A vertical scroll 15° off vertical.
76 + const drift = Array.from({ length: 30 }, () => [-4, 15] as const);
77 + it.each([
78 + [
79 + "a vertical scroll that starts slightly diagonally keeps the thread",
80 + [[-5, 3], ...drift],
81 + false,
82 + ],
83 + [
84 + "a swipe that leans diagonally for two events navigates",
85 + [
86 + [-5, 3],
87 + [-2, 2],
88 + [-150, 0],
89 + ],
90 + true,
91 + ],
92 + ["a single diagonal event past the trigger keeps the thread", [[-130, 100]], false],
93 + ] as const)("%s", async (_name, events, navigates) => {
94 + navigateHistory.mockReset();
95 + using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
96 + await using screen = await render(<HistorySwipeNavigation />);
97 + const panel = screen.container.appendChild(document.createElement("div"));
98 + for (const [deltaX, deltaY] of [...events, [0, 0] as const]) {
99 + panel.dispatchEvent(
100 + new WheelEvent("wheel", { deltaX, deltaY, bubbles: true, composed: true }),
101 + );
102 + }
103 +
104 + expect(navigateHistory).toHaveBeenCalledTimes(navigates ? 1 : 0);
105 + });
106 });
apps/web/src/components/HistorySwipeNavigation.tsx
+23 -1
@@ -7,6 +7,10 @@ import { canNavigateHistory, navigateHistory, type HistoryDirection } from "../n
7 const SWIPE_TRIGGER_DISTANCE = 120;
8 // Movement needed before the gesture picks an axis; first events are often diagonal.
9 const SWIPE_AXIS_LOCK_DISTANCE = 8;
10 +// Vertical scrolls drift sideways, so a swipe's horizontal travel must clearly dominate once
11 +// it has moved far enough for its direction to be more than noise.
12 +const SWIPE_HORIZONTAL_DOMINANCE = 2;
13 +const SWIPE_DOMINANCE_DISTANCE = 30;
14 const MOMENTUM_SAMPLE_SIZE = 5;
15
16 type SwipeBounds = { left: number; top: number; width: number; height: number };
@@ -17,6 +21,8 @@ type SwipeGesture =
21 direction: HistoryDirection;
22 distance: number;
23 deltas: number[];
24 + travelX: number;
25 + travelY: number;
26 y: number;
27 bounds: SwipeBounds;
28 }
@@ -52,11 +58,19 @@ function canScrollHorizontally(path: readonly EventTarget[], deltaX: number): bo
58 return false;
59 }
60
61 +function isVerticalScroll(travelX: number, travelY: number): boolean {
62 + return (
63 + travelX + travelY >= SWIPE_DOMINANCE_DISTANCE && travelX <= SWIPE_HORIZONTAL_DOMINANCE * travelY
64 + );
65 +}
66 +
67 function lockSwipeAxis(
68 pending: Extract<SwipeGesture, { kind: "pending" }>,
69 ): Exclude<SwipeGesture, { kind: "pending" }> {
70 const { path, sumX, sumY } = pending;
59 - if (Math.abs(sumX) <= Math.abs(sumY)) return { kind: "ignored" };
71 + if (Math.abs(sumX) <= Math.abs(sumY) || isVerticalScroll(Math.abs(sumX), Math.abs(sumY))) {
72 + return { kind: "ignored" };
73 + }
74 if (path.some((node) => node instanceof Element && node.matches('[role="dialog"]'))) {
75 return { kind: "ignored" };
76 }
@@ -68,6 +82,8 @@ function lockSwipeAxis(
82 direction,
83 distance: Math.abs(sumX),
84 deltas: [],
85 + travelX: Math.abs(sumX),
86 + travelY: Math.abs(sumY),
87 y: pending.y,
88 bounds: readMainContentBounds(),
89 };
@@ -134,6 +150,12 @@ export function HistorySwipeNavigation() {
150 } else {
151 const delta = gesture.direction === "back" ? -event.deltaX : event.deltaX;
152 if (event.deltaX === 0 && event.deltaY === 0) return release();
153 + gesture.travelX += Math.abs(event.deltaX);
154 + gesture.travelY += Math.abs(event.deltaY);
155 + if (isVerticalScroll(gesture.travelX, gesture.travelY)) {
156 + gesture = { kind: "ignored" };
157 + return hideIndicator();
158 + }
159 gesture.deltas = [...gesture.deltas.slice(1 - MOMENTUM_SAMPLE_SIZE), delta];
160 if (isMomentumTail(gesture.deltas)) return release();
161 gesture.distance = Math.max(0, gesture.distance + delta);