From 4687e139403d71bb9ccab0b3f09dc7e2b79c27ff Mon Sep 17 00:00:00 2001 From: ernest0n Date: Thu, 19 Nov 2026 15:54:17 +0400 Subject: [PATCH] fix(web): trackpad swipe no longer switches threads after scrolling a code pane A two-finger swipe that started at the edge of a horizontal scroller locked into thread navigation after its first 8px and was never re-checked, so reversing direction scrolled the pane while the same gesture still switched threads on release. While a swipe is tracked, a horizontal movement that a scroller under the pointer can absorb now ends history handling for the rest of the gesture. A swipe that starts at the edge and never scrolls the pane still navigates. Made-with: claudeAgent/claude-opus-5-5 --- .../HistorySwipeNavigation.browser.test.tsx | 32 +++++++++++++++++++ .../src/components/HistorySwipeNavigation.tsx | 5 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx b/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx index d2a15729b0df..7149564a4993 100644 --- a/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx +++ b/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx @@ -60,6 +60,38 @@ describe("HistorySwipeNavigation", () => { expect(navigateHistory).toHaveBeenCalledTimes(navigates ? 1 : 0); }); + it.each([ + [ + "reversing over a scroller after swiping forward at its right edge keeps the thread", + 800, + [20, -50, 140], + ], + [ + "reversing over a scroller after swiping back at its left edge keeps the thread", + 0, + [-20, 50, -140], + ], + ] as const)("%s", async (_name, scrollLeft, deltas) => { + navigateHistory.mockReset(); + using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel"); + await using screen = await render(); + const viewport = screen.container.appendChild(document.createElement("div")); + viewport.style.cssText = "width: 200px; overflow-x: auto"; + const content = viewport.appendChild(document.createElement("div")); + content.style.cssText = "height: 20px; width: 1000px"; + viewport.scrollLeft = scrollLeft; + // Synthetic wheel events do not scroll natively. + viewport.addEventListener("wheel", (event) => { + viewport.scrollLeft += event.deltaX; + }); + + for (const deltaX of [...deltas, 0]) { + content.dispatchEvent(new WheelEvent("wheel", { deltaX, bubbles: true, composed: true })); + } + + expect(navigateHistory).not.toHaveBeenCalled(); + }); + it("a horizontal mouse wheel tick off macOS keeps the thread", async () => { navigateHistory.mockReset(); using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("Win32"); diff --git a/apps/web/src/components/HistorySwipeNavigation.tsx b/apps/web/src/components/HistorySwipeNavigation.tsx index 2924f82cd313..1d5a86094120 100644 --- a/apps/web/src/components/HistorySwipeNavigation.tsx +++ b/apps/web/src/components/HistorySwipeNavigation.tsx @@ -152,7 +152,10 @@ export function HistorySwipeNavigation() { if (event.deltaX === 0 && event.deltaY === 0) return release(); gesture.travelX += Math.abs(event.deltaX); gesture.travelY += Math.abs(event.deltaY); - if (isVerticalScroll(gesture.travelX, gesture.travelY)) { + if ( + isVerticalScroll(gesture.travelX, gesture.travelY) || + (event.deltaX !== 0 && canScrollHorizontally(event.composedPath(), event.deltaX)) + ) { gesture = { kind: "ignored" }; return hideIndicator(); }