Skip to content
Open
98 changes: 94 additions & 4 deletions apps/web/src/components/AppSidebarLayout.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { page, userEvent } from "vite-plus/test/browser";
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
import { describe, expect, it, vi } from "vite-plus/test";

import { render } from "../../test/render";
import { act, render } from "../../test/render";
import {
__resetClientSettingsPersistenceForTests,
__setClientSettingsForTests,
updateClientSettings,
} from "../hooks/useSettings";
import { AppSidebarLayout } from "./AppSidebarLayout";

vi.mock(import("../state/server"), async (original) => {
const actual = await original();
Expand All @@ -12,10 +19,93 @@ vi.mock(import("../state/server"), async (original) => {
]);
return { ...actual, primaryServerKeybindingsAtom: Atom.make(keybindings) };
});
// The thread list needs live environments; the shortcut lives in the shell around it.
vi.mock(import("./Sidebar"), () => ({ default: (() => null) as never }));
vi.mock("../env", () => ({ isElectron: true }));
vi.mock("./Sidebar", () => ({ default: () => null }));
vi.mock("./BackgroundThreadAnnouncer", () => ({ BackgroundThreadAnnouncer: () => null }));
vi.mock("./sidebar/SidebarChrome", () => ({ SidebarBrandWidthProbe: () => null }));
const storedSettings = vi.hoisted(() => ({ current: Promise.resolve<unknown>(null) }));

import { AppSidebarLayout } from "./AppSidebarLayout";
vi.mock("../localApi", () => ({
ensureLocalApi: () => ({
persistence: {
getClientSettings: () => storedSettings.current,
setClientSettings: async () => undefined,
},
}),
}));

function setup(historySwipeNavigation: boolean) {
storedSettings.current = Promise.resolve(null);
__resetClientSettingsPersistenceForTests();
__setClientSettingsForTests({ ...DEFAULT_CLIENT_SETTINGS, historySwipeNavigation });
}

function wheel(deltaX: number) {
window.dispatchEvent(new WheelEvent("wheel", { deltaX, clientY: 200 }));
}

describe("desktop history swipe navigation", () => {
it.each(["back", "forward"] as const)(
"disables %s swipes and can re-enable them without reloading",
async (direction) => {
setup(false);
using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
using _available = vi
.spyOn(window.navigation, direction === "back" ? "canGoBack" : "canGoForward", "get")
.mockReturnValue(true);
await using screen = await render(<AppSidebarLayout>Thread</AppSidebarLayout>);
using navigate = vi.spyOn(window.history, direction).mockImplementation(() => undefined);
const deltaX = direction === "back" ? -140 : 140;

await act(() => {
wheel(deltaX);
wheel(0);
});
expect(navigate).not.toHaveBeenCalled();
await expect.element(screen.getByTestId("history-swipe-indicator")).not.toBeInTheDocument();

await act(() => updateClientSettings({ historySwipeNavigation: true }));
await act(() => wheel(deltaX));
await expect.element(screen.getByTestId("history-swipe-indicator")).toBeInTheDocument();

await act(() => updateClientSettings({ historySwipeNavigation: false }));
await expect.element(screen.getByTestId("history-swipe-indicator")).not.toBeInTheDocument();
await act(() => wheel(0));
expect(navigate).not.toHaveBeenCalled();

await act(() => updateClientSettings({ historySwipeNavigation: true }));
await act(() => {
wheel(deltaX);
wheel(0);
});
expect(navigate).toHaveBeenCalledOnce();
},
);

it("keeps swipes off until the saved settings load", async () => {
const saved = Promise.withResolvers<unknown>();
storedSettings.current = saved.promise;
__resetClientSettingsPersistenceForTests();
using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
using _available = vi.spyOn(window.navigation, "canGoBack", "get").mockReturnValue(true);
await using _screen = await render(<AppSidebarLayout>Thread</AppSidebarLayout>);
using navigate = vi.spyOn(window.history, "back").mockImplementation(() => undefined);

await act(() => {
wheel(-140);
wheel(0);
});
expect(navigate).not.toHaveBeenCalled();

saved.resolve({ historySwipeNavigation: false });
await act(() => saved.promise);
await act(() => {
wheel(-140);
wheel(0);
});
expect(navigate).not.toHaveBeenCalled();
});
});

describe("sidebar toggle shortcut", () => {
it("leaves the key to a focused terminal when its rule excludes terminalFocus", async () => {
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/components/AppSidebarLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
import { cn, isMacPlatform } from "../lib/utils";
import { primaryServerKeybindingsAtom } from "../state/server";
import { useEnvironmentIdentificationMode } from "../hooks/useSettings";
import {
useClientSettings,
useClientSettingsHydrated,
useEnvironmentIdentificationMode,
} from "../hooks/useSettings";
import {
PanelAnimationSuppressionProvider,
usePanelAnimationSettings,
Expand Down Expand Up @@ -425,6 +429,8 @@ export function AppSidebarLayout({
showSidebar?: boolean;
}) {
const gt = useGT();
const historySwipeNavigation = useClientSettings((settings) => settings.historySwipeNavigation);
const settingsHydrated = useClientSettingsHydrated();
const sidebarArea = workspaceAreaProps("sidebar", 0, gt("Threads"));
const [sidebarRouteReveal] = useState<SidebarRouteReveal>(() => ({
observedKey: null,
Expand Down Expand Up @@ -502,7 +508,9 @@ export function AppSidebarLayout({
{children}
<BackgroundThreadAnnouncer />
<SidebarControl showSidebar={showSidebar} />
{isElectron ? <HistorySwipeNavigation /> : null}
{isElectron && settingsHydrated && historySwipeNavigation ? (
<HistorySwipeNavigation />
) : null}
</SidebarProvider>
</PanelAnimationSuppressionProvider>
);
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/HistorySwipeNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function SwipeIndicator({ direction, progress, y, bounds, tracking }: SwipeIndic
return (
<div
aria-hidden="true"
data-testid="history-swipe-indicator"
className="pointer-events-none fixed z-100 overflow-hidden"
style={bounds}
>
Expand Down
37 changes: 37 additions & 0 deletions apps/web/src/components/settings/SettingsPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ export function useSettingsRestore(onRestored?: () => void) {
? [gt("Delete confirmation")]
: []),
...(settings.confirmQuit !== DEFAULT_UNIFIED_SETTINGS.confirmQuit ? [gt("Quit shortcut")] : []),
...(settings.historySwipeNavigation !== DEFAULT_UNIFIED_SETTINGS.historySwipeNavigation
? [gt("Swipe to navigate")]
: []),
...(isTextGenerationModelDirty ? [gt("Text generation model")] : []),
...(settings.threadTitleInstructions !== DEFAULT_UNIFIED_SETTINGS.threadTitleInstructions
? [gt("Thread title instructions")]
Expand Down Expand Up @@ -758,6 +761,7 @@ export function useSettingsRestore(onRestored?: () => void) {
confirmThreadDelete: DEFAULT_UNIFIED_SETTINGS.confirmThreadDelete,
confirmThreadUnpin: DEFAULT_UNIFIED_SETTINGS.confirmThreadUnpin,
confirmQuit: DEFAULT_UNIFIED_SETTINGS.confirmQuit,
historySwipeNavigation: DEFAULT_UNIFIED_SETTINGS.historySwipeNavigation,
textGenerationModelSelection: DEFAULT_UNIFIED_SETTINGS.textGenerationModelSelection,
threadTitleInstructions: DEFAULT_UNIFIED_SETTINGS.threadTitleInstructions,
fontFamilySans: DEFAULT_UNIFIED_SETTINGS.fontFamilySans,
Expand Down Expand Up @@ -983,6 +987,39 @@ export function GeneralSettingsPanel() {
/>
</SettingsSection>

{isElectron && isMacPlatform(navigator.platform) ? (
<SettingsSection id="navigation" title={gt("Navigation")}>
<SettingsRow
{...setting("history-swipe-navigation")}
description={
<T>Swipe horizontally with two fingers on a trackpad to go back or forward.</T>
}
resetAction={
settings.historySwipeNavigation !==
DEFAULT_UNIFIED_SETTINGS.historySwipeNavigation ? (
<SettingResetButton
ariaLabel={gt("Reset swipe navigation to default")}
onClick={() =>
updateSettings({
historySwipeNavigation: DEFAULT_UNIFIED_SETTINGS.historySwipeNavigation,
})
}
/>
) : null
}
control={
<Switch
checked={settings.historySwipeNavigation}
onCheckedChange={(checked) =>
updateSettings({ historySwipeNavigation: Boolean(checked) })
}
aria-label={gt("Swipe to navigate")}
/>
}
/>
</SettingsSection>
) : null}

<SettingsSection id="confirmations" title={gt("Confirmations")}>
<SettingsRow
{...setting("unpin-confirmation")}
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/settings/settingsSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ describe("searchSettings", () => {

it("hides desktop-only settings from browser search", () => {
expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "history-swipe-navigation")).toBe(true);
expect(searchSettings("horizontal wheel")).toEqual([]);
expect(searchSettings("hold to quit")).toEqual([]);
expect(searchSettings("wsl")).toEqual([]);
expect(searchSettings("update track")).toEqual([]);
Expand Down
12 changes: 12 additions & 0 deletions apps/web/src/components/settings/settingsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,18 @@ export const SETTINGS_SEARCH_ITEMS = [
searchTerms: [msg("confirmation desktop app exit direct hold double click press twice")],
desktopOnly: true,
},
{
id: "history-swipe-navigation",
title: msg("Swipe to navigate"),
to: "/settings/general",
searchTerms: [
msg(
"two-finger horizontal trackpad gesture mouse wheel back forward thread history navigation",
),
],
desktopOnly: true,
macOnly: true,
},
{
id: "text-generation-model",
title: msg("Text generation model"),
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -10129,6 +10129,7 @@
"5503ef439beb8d42": "Bestätigung beim Schließen von Terminals",
"d5dd27a4eb853248": "Löschen bestätigen",
"86b43caa9ff41ea2": "Tastenkürzel zum Beenden",
"ebabe529ac6fbf67": "Zum Navigieren wischen",
"cf4973ea5bda78ac": "Anweisungen für Thread-Titel",
"7be0e8cf7e371977": "Standardeinstellungen wiederherstellen?",
"31c08fdf005eb2ba": "Dadurch wird zurückgesetzt: {settings}.",
Expand All @@ -10139,6 +10140,7 @@
"cd5452cc9e13c818": "Projektgruppierung",
"cfb01b8a2a3361fb": "Projektreihenfolge auf Standard zurücksetzen",
"26abcbe322049a8a": "Bereich „In Arbeit“ auf Standard zurücksetzen",
"88403fa251ee5dab": "Wisch-Navigation auf Standard zurücksetzen",
"76f3c3e2f8dd0120": "Bestätigungen",
"caed837d6dc42548": "Bestätigung beim Loslösen auf Standard zurücksetzen",
"859e386f8af841f0": "Loslösen von Threads bestätigen",
Expand Down Expand Up @@ -10248,6 +10250,7 @@
"83ca942c7163904f": "Gleiche Repositorys aus verschiedenen Umgebungen zusammenfassen.",
"609da998ca13521e": "Reihenfolge der Projekte in der Projektauswahl der Seitenleiste und in der Befehlspalette.",
"b4c541137a76b351": "Laufende und überwachende Threads im Bereich „In Arbeit“ bündeln. Sie rücken im Posteingang wieder nach oben, sobald sie dich brauchen. Die schlichte Seitenleiste unter Labs hat keinen Bereich „In Arbeit“.",
"7abcb8005c471e4f": "Wische mit zwei Fingern horizontal über das Trackpad, um zurück oder vorwärts zu navigieren.",
"e815f49e5abedcfd": "Vor dem Loslösen eines Threads aus dem Bereich „Angeheftet“ nachfragen.",
"41210f99adeeba78": "Einen zweiten Klick auf die Archivieren-Aktion verlangen, bevor ein Thread archiviert wird.",
"84f3d2cefc8d2a74": "Vor dem Löschen eines Threads samt Chatverlauf nachfragen.",
Expand Down Expand Up @@ -11909,6 +11912,7 @@
"53390c9ebb75f5d3": "vorher fragen thread zweiter klick inline aktion",
"a26bd55959bfa3d3": "vorher fragen thread chatverlauf",
"de504407a9dfe3bd": "bestätigung desktop app beenden direkt halten doppelklick zweimal drücken",
"8132643b1924a3e1": "zwei Finger horizontal Trackpad Geste Maus Mausrad zurück vorwärts Thread Verlauf Navigation",
"a8a6da6439b8333e": "generierte thread-titel versionskontrolle inhalt standard anbieter",
"0c5fc3b5e41e1956": "generierte thread-titel prompt benutzerdefiniert stil benennung umbenennen neu generieren",
"a83570bcb45d8fa1": "info nach updates suchen herunterladen installieren upgrade version",
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10138,6 +10138,7 @@
"5503ef439beb8d42": "Terminal close confirmation",
"d5dd27a4eb853248": "Delete confirmation",
"86b43caa9ff41ea2": "Quit shortcut",
"ebabe529ac6fbf67": "Swipe to navigate",
"cf4973ea5bda78ac": "Thread title instructions",
"7be0e8cf7e371977": "Restore default settings?",
"31c08fdf005eb2ba": "This will reset: {settings}.",
Expand All @@ -10148,6 +10149,7 @@
"cd5452cc9e13c818": "Project grouping",
"cfb01b8a2a3361fb": "Reset project order to default",
"26abcbe322049a8a": "Reset working section to default",
"88403fa251ee5dab": "Reset swipe navigation to default",
"76f3c3e2f8dd0120": "Confirmations",
"caed837d6dc42548": "Reset unpin confirmation to default",
"859e386f8af841f0": "Confirm thread unpinning",
Expand Down Expand Up @@ -10257,6 +10259,7 @@
"83ca942c7163904f": "Combine matching repositories across environments.",
"609da998ca13521e": "Order of projects in the sidebar project picker and command palette.",
"b4c541137a76b351": "Fold working and monitoring threads into a Working section. They return to the top of the inbox when they need you. The boring sidebar in Labs has no Working section.",
"7abcb8005c471e4f": "Swipe horizontally with two fingers on a trackpad to go back or forward.",
"e815f49e5abedcfd": "Ask before unpinning a thread from the pinned section.",
"41210f99adeeba78": "Require a second click on the inline archive action before a thread is archived.",
"84f3d2cefc8d2a74": "Ask before deleting a thread and its chat history.",
Expand Down Expand Up @@ -11917,6 +11920,7 @@
"53390c9ebb75f5d3": "ask before thread second click inline action",
"a26bd55959bfa3d3": "ask before thread chat history",
"de504407a9dfe3bd": "confirmation desktop app exit direct hold double click press twice",
"8132643b1924a3e1": "two-finger horizontal trackpad gesture mouse wheel back forward thread history navigation",
"a8a6da6439b8333e": "generated thread titles source control content default provider",
"0c5fc3b5e41e1956": "generated thread titles prompt custom style naming rename regenerate",
"a83570bcb45d8fa1": "about check for updates download install upgrade release",
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -10126,6 +10126,7 @@
"5503ef439beb8d42": "Confirmación al cerrar terminales",
"d5dd27a4eb853248": "Confirmación al eliminar",
"86b43caa9ff41ea2": "Atajo para salir",
"ebabe529ac6fbf67": "Deslizar para navegar",
"cf4973ea5bda78ac": "Instrucciones para los títulos de hilos",
"7be0e8cf7e371977": "¿Restaurar los ajustes predeterminados?",
"31c08fdf005eb2ba": "Se restablecerá: {settings}.",
Expand All @@ -10136,6 +10137,7 @@
"cd5452cc9e13c818": "Agrupación de proyectos",
"cfb01b8a2a3361fb": "Restablecer el orden de proyectos al valor predeterminado",
"26abcbe322049a8a": "Restablecer la sección En curso al valor predeterminado",
"88403fa251ee5dab": "Restablecer la navegación por deslizamiento al valor predeterminado",
"76f3c3e2f8dd0120": "Confirmaciones",
"caed837d6dc42548": "Restablecer la confirmación al desfijar al valor predeterminado",
"859e386f8af841f0": "Confirmar al desfijar hilos",
Expand Down Expand Up @@ -10245,6 +10247,7 @@
"83ca942c7163904f": "Combina los repositorios coincidentes de distintos entornos.",
"609da998ca13521e": "Orden de los proyectos en el selector de la barra lateral y en la paleta de comandos.",
"b4c541137a76b351": "Agrupa los hilos activos y en seguimiento en la sección En curso. Vuelven arriba de la bandeja de entrada cuando te necesitan. La barra lateral simple (en Experimentos) no tiene sección En curso.",
"7abcb8005c471e4f": "Desliza dos dedos horizontalmente sobre el trackpad para ir atrás o adelante.",
"e815f49e5abedcfd": "Pregunta antes de desfijar un hilo de la sección de fijados.",
"41210f99adeeba78": "Pide un segundo clic en la acción de archivar antes de archivar un hilo.",
"84f3d2cefc8d2a74": "Pregunta antes de eliminar un hilo y su historial de chat.",
Expand Down Expand Up @@ -11902,6 +11905,7 @@
"53390c9ebb75f5d3": "preguntar antes hilo segundo clic acción en línea",
"a26bd55959bfa3d3": "preguntar antes hilo historial de chat",
"de504407a9dfe3bd": "confirmación app de escritorio salir directo mantener doble clic pulsar dos veces",
"8132643b1924a3e1": "dos dedos horizontal trackpad gesto ratón rueda atrás adelante hilo historial navegación",
"a8a6da6439b8333e": "títulos de hilos generados control de versiones contenido proveedor predeterminado",
"0c5fc3b5e41e1956": "títulos de hilos generados prompt estilo personalizado nombres renombrar regenerar",
"a83570bcb45d8fa1": "acerca de buscar actualizaciones descargar instalar actualizar versión",
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10128,6 +10128,7 @@
"5503ef439beb8d42": "Confirmation de fermeture des terminaux",
"d5dd27a4eb853248": "Confirmation de la suppression",
"86b43caa9ff41ea2": "Raccourci Quitter",
"ebabe529ac6fbf67": "Balayer pour naviguer",
"cf4973ea5bda78ac": "Instructions pour le titre des fils",
"7be0e8cf7e371977": "Restaurer les paramètres par défaut ?",
"31c08fdf005eb2ba": "Seront réinitialisés : {settings}.",
Expand All @@ -10138,6 +10139,7 @@
"cd5452cc9e13c818": "Regroupement des projets",
"cfb01b8a2a3361fb": "Réinitialiser l’ordre des projets à la valeur par défaut",
"26abcbe322049a8a": "Réinitialiser la section En cours à la valeur par défaut",
"88403fa251ee5dab": "Rétablir la navigation par balayage par défaut",
"76f3c3e2f8dd0120": "Confirmations",
"caed837d6dc42548": "Réinitialiser la confirmation avant de désépingler à la valeur par défaut",
"859e386f8af841f0": "Confirmer avant de désépingler un fil",
Expand Down Expand Up @@ -10247,6 +10249,7 @@
"83ca942c7163904f": "Regroupe les dépôts identiques de tous les environnements.",
"609da998ca13521e": "Ordre des projets dans le sélecteur de la barre latérale et dans la palette de commandes.",
"b4c541137a76b351": "Regroupe les fils en cours et en surveillance dans une section En cours. Ils reviennent en haut de la boîte de réception quand ils ont besoin de vous. La barre latérale classique de Labs n’a pas de section En cours.",
"7abcb8005c471e4f": "Balayez horizontalement le pavé tactile avec deux doigts pour revenir en arrière ou avancer.",
"e815f49e5abedcfd": "Demande confirmation avant de désépingler un fil.",
"41210f99adeeba78": "Exige un second clic sur le bouton d’archivage du fil avant de l’archiver.",
"84f3d2cefc8d2a74": "Demande confirmation avant de supprimer un fil et son historique de discussion.",
Expand Down Expand Up @@ -11907,6 +11910,7 @@
"53390c9ebb75f5d3": "demander avant fil second clic action en ligne",
"a26bd55959bfa3d3": "demander avant fil historique de discussion",
"de504407a9dfe3bd": "confirmation app de bureau quitter direct maintenir double clic appuyer deux fois",
"8132643b1924a3e1": "deux doigts horizontal pavé tactile geste souris molette arrière avant fil historique navigation",
"a8a6da6439b8333e": "titres de fils générés gestion de versions contenu fournisseur par défaut",
"0c5fc3b5e41e1956": "titres de fils générés prompt style personnalisé nommage renommer régénérer",
"a83570bcb45d8fa1": "à propos rechercher des mises à jour télécharger installer mettre à niveau version",
Expand Down
Loading
Loading