Skip to content

Commit db2a71b

Browse files
committed
feat(web): add a setting to disable history swipe navigation
Horizontal mouse wheels can accidentally navigate desktop thread history. Electron input events do not distinguish a trackpad swipe from a mouse wheel. Add a default-enabled client setting with desktop Settings search and reset support. Unmount the gesture handler when disabled, and cover disabling, mid-swipe cleanup, and re-enabling with focused regression tests. Model: gpt-6.1-sol via Codex CLI, orchestrated by Claude Code.
1 parent 15fe283 commit db2a71b

8 files changed

Lines changed: 130 additions & 2 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
2+
import { describe, expect, it, vi } from "vite-plus/test";
3+
4+
import { act, render } from "../../test/render";
5+
import {
6+
__resetClientSettingsPersistenceForTests,
7+
__setClientSettingsForTests,
8+
updateClientSettings,
9+
} from "../hooks/useSettings";
10+
import { AppSidebarLayout } from "./AppSidebarLayout";
11+
12+
vi.mock("../env", () => ({ isElectron: true }));
13+
vi.mock("./Sidebar", () => ({ default: () => null }));
14+
vi.mock("./BackgroundThreadAnnouncer", () => ({ BackgroundThreadAnnouncer: () => null }));
15+
vi.mock("./sidebar/SidebarChrome", () => ({ SidebarBrandWidthProbe: () => null }));
16+
vi.mock("../localApi", () => ({
17+
ensureLocalApi: () => ({
18+
persistence: { setClientSettings: async () => undefined },
19+
}),
20+
}));
21+
22+
function setup(historySwipeNavigation: boolean) {
23+
__resetClientSettingsPersistenceForTests();
24+
__setClientSettingsForTests({ ...DEFAULT_CLIENT_SETTINGS, historySwipeNavigation });
25+
}
26+
27+
function wheel(deltaX: number) {
28+
window.dispatchEvent(new WheelEvent("wheel", { deltaX, clientY: 200 }));
29+
}
30+
31+
describe("desktop history swipe navigation", () => {
32+
it.each(["back", "forward"] as const)(
33+
"disables %s swipes and can re-enable them without reloading",
34+
async (direction) => {
35+
setup(false);
36+
using _available = vi
37+
.spyOn(window.navigation, direction === "back" ? "canGoBack" : "canGoForward", "get")
38+
.mockReturnValue(true);
39+
await using screen = await render(<AppSidebarLayout>Thread</AppSidebarLayout>);
40+
using navigate = vi.spyOn(window.history, direction).mockImplementation(() => undefined);
41+
const deltaX = direction === "back" ? -140 : 140;
42+
43+
await act(() => {
44+
wheel(deltaX);
45+
wheel(0);
46+
});
47+
expect(navigate).not.toHaveBeenCalled();
48+
await expect.element(screen.getByTestId("history-swipe-indicator")).not.toBeInTheDocument();
49+
50+
await act(() => updateClientSettings({ historySwipeNavigation: true }));
51+
await act(() => wheel(deltaX));
52+
await expect.element(screen.getByTestId("history-swipe-indicator")).toBeInTheDocument();
53+
54+
await act(() => updateClientSettings({ historySwipeNavigation: false }));
55+
await expect.element(screen.getByTestId("history-swipe-indicator")).not.toBeInTheDocument();
56+
await act(() => wheel(0));
57+
expect(navigate).not.toHaveBeenCalled();
58+
59+
await act(() => updateClientSettings({ historySwipeNavigation: true }));
60+
await act(() => {
61+
wheel(deltaX);
62+
wheel(0);
63+
});
64+
expect(navigate).toHaveBeenCalledOnce();
65+
},
66+
);
67+
});

‎apps/web/src/components/AppSidebarLayout.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
3131
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
3232
import { cn, isMacPlatform } from "../lib/utils";
3333
import { primaryServerKeybindingsAtom } from "../state/server";
34-
import { useEnvironmentIdentificationMode } from "../hooks/useSettings";
34+
import { useClientSettings, useEnvironmentIdentificationMode } from "../hooks/useSettings";
3535
import {
3636
PanelAnimationSuppressionProvider,
3737
usePanelAnimationSettings,
@@ -402,6 +402,7 @@ function SidebarControl() {
402402
}
403403

404404
export function AppSidebarLayout({ children }: { children: ReactNode }) {
405+
const historySwipeNavigation = useClientSettings((settings) => settings.historySwipeNavigation);
405406
const sidebarArea = workspaceAreaProps("sidebar", 0, "Threads");
406407
const [sidebarRouteReveal] = useState<SidebarRouteReveal>(() => ({
407408
observedKey: null,
@@ -475,7 +476,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
475476
{children}
476477
<BackgroundThreadAnnouncer />
477478
<SidebarControl />
478-
{isElectron ? <HistorySwipeNavigation /> : null}
479+
{isElectron && historySwipeNavigation ? <HistorySwipeNavigation /> : null}
479480
</SidebarProvider>
480481
</PanelAnimationSuppressionProvider>
481482
);

‎apps/web/src/components/HistorySwipeNavigation.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function SwipeIndicator({ direction, progress, y, bounds, tracking }: SwipeIndic
162162
return (
163163
<div
164164
aria-hidden="true"
165+
data-testid="history-swipe-indicator"
165166
className="pointer-events-none fixed z-100 overflow-hidden"
166167
style={bounds}
167168
>

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ export function useSettingsRestore(onRestored?: () => void) {
536536
? ["Delete confirmation"]
537537
: []),
538538
...(settings.confirmQuit !== DEFAULT_UNIFIED_SETTINGS.confirmQuit ? ["Quit shortcut"] : []),
539+
...(settings.historySwipeNavigation !== DEFAULT_UNIFIED_SETTINGS.historySwipeNavigation
540+
? ["Swipe to go back and forward"]
541+
: []),
539542
...(isTextGenerationModelDirty ? ["Text generation model"] : []),
540543
...(settings.threadTitleInstructions !== DEFAULT_UNIFIED_SETTINGS.threadTitleInstructions
541544
? ["Thread title instructions"]
@@ -643,6 +646,7 @@ export function useSettingsRestore(onRestored?: () => void) {
643646
confirmThreadDelete: DEFAULT_UNIFIED_SETTINGS.confirmThreadDelete,
644647
confirmThreadUnpin: DEFAULT_UNIFIED_SETTINGS.confirmThreadUnpin,
645648
confirmQuit: DEFAULT_UNIFIED_SETTINGS.confirmQuit,
649+
historySwipeNavigation: DEFAULT_UNIFIED_SETTINGS.historySwipeNavigation,
646650
textGenerationModelSelection: DEFAULT_UNIFIED_SETTINGS.textGenerationModelSelection,
647651
threadTitleInstructions: DEFAULT_UNIFIED_SETTINGS.threadTitleInstructions,
648652
fontFamilySans: DEFAULT_UNIFIED_SETTINGS.fontFamilySans,
@@ -880,6 +884,37 @@ export function GeneralSettingsPanel() {
880884
/>
881885
</SettingsSection>
882886

887+
{isElectron ? (
888+
<SettingsSection id="navigation" title="Navigation">
889+
<SettingsRow
890+
{...searchableSetting("history-swipe-navigation")}
891+
description="Two-finger horizontal swipes move through your thread history. Turn off if a mouse with a horizontal wheel switches threads by accident."
892+
resetAction={
893+
settings.historySwipeNavigation !==
894+
DEFAULT_UNIFIED_SETTINGS.historySwipeNavigation ? (
895+
<SettingResetButton
896+
label="swipe navigation"
897+
onClick={() =>
898+
updateSettings({
899+
historySwipeNavigation: DEFAULT_UNIFIED_SETTINGS.historySwipeNavigation,
900+
})
901+
}
902+
/>
903+
) : null
904+
}
905+
control={
906+
<Switch
907+
checked={settings.historySwipeNavigation}
908+
onCheckedChange={(checked) =>
909+
updateSettings({ historySwipeNavigation: Boolean(checked) })
910+
}
911+
aria-label="Swipe to go back and forward"
912+
/>
913+
}
914+
/>
915+
</SettingsSection>
916+
) : null}
917+
883918
<SettingsSection id="confirmations" title="Confirmations">
884919
<SettingsRow
885920
{...searchableSetting("unpin-confirmation")}

‎apps/web/src/components/settings/settingsSearch.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ describe("searchSettings", () => {
9999

100100
it("hides desktop-only settings from browser search", () => {
101101
expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
102+
expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "history-swipe-navigation")).toBe(true);
103+
expect(searchSettings("horizontal wheel")).toEqual([]);
102104
expect(searchSettings("hold to quit")).toEqual([]);
103105
expect(searchSettings("wsl")).toEqual([]);
104106
expect(searchSettings("update track")).toEqual([]);

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,13 @@ export const SETTINGS_SEARCH_ITEMS = [
668668
searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
669669
desktopOnly: true,
670670
},
671+
{
672+
id: "history-swipe-navigation",
673+
title: "Swipe to go back and forward",
674+
to: "/settings/general",
675+
searchTerms: ["two-finger horizontal trackpad gesture mouse wheel thread history navigation"],
676+
desktopOnly: true,
677+
},
671678
{
672679
id: "text-generation-model",
673680
title: "Text generation model",

‎packages/contracts/src/settings.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ describe("ClientSettings quit confirmation", () => {
303303
});
304304
});
305305

306+
describe("ClientSettings history swipe navigation", () => {
307+
it.each([undefined, true, false])("decodes and round-trips %s", (historySwipeNavigation) => {
308+
const input = historySwipeNavigation === undefined ? {} : { historySwipeNavigation };
309+
const settings = decodeClientSettings(input);
310+
311+
expect(settings.historySwipeNavigation).toBe(historySwipeNavigation ?? true);
312+
expect(decodeClientSettings(encodeClientSettings(settings)).historySwipeNavigation).toBe(
313+
historySwipeNavigation ?? true,
314+
);
315+
expect(decodeClientSettingsPatch(input)).toEqual(input);
316+
});
317+
});
318+
306319
describe("provider enabled defaults", () => {
307320
it("resolves instance enabled state with explicit false winning", () => {
308321
const grok = ProviderDriverKind.make("grok");

‎packages/contracts/src/settings.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ export const ClientSettingsSchema = Schema.Struct({
444444
fontFamilyTerminal: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
445445

446446
fontSmoothing: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
447+
historySwipeNavigation: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
447448
// Older installs also decode to null; onboarding must additionally require an empty workspace.
448449
onboardingCompletedAt: Schema.NullOr(Schema.String).pipe(
449450
Schema.withDecodingDefault(Effect.succeed(null)),
@@ -1759,6 +1760,7 @@ export const ClientSettingsPatch = Schema.Struct({
17591760
fontFamilySans: Schema.optionalKey(FontFamilyPreference),
17601761
fontFamilyTerminal: Schema.optionalKey(FontFamilyPreference),
17611762
fontSmoothing: Schema.optionalKey(Schema.Boolean),
1763+
historySwipeNavigation: Schema.optionalKey(Schema.Boolean),
17621764
persistComposerContextStrip: Schema.optionalKey(Schema.Boolean),
17631765
favorites: Schema.optionalKey(ModelFavorites),
17641766
providerModelPreferences: Schema.optionalKey(ProviderModelPreferences),

0 commit comments

Comments
 (0)