From f0fc5e6ed75f634a6518eafc0b0aabdf319e3e1d Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:25:03 -0500 Subject: [PATCH] feat(frontend): add an app-wide font size preference --- backend/src/services/assistant-mode.ts | 1 + frontend/index.html | 2 ++ .../components/settings/GeneralSettings.tsx | 29 +++++++++++++++++++ frontend/src/contexts/ThemeContext.tsx | 9 +++++- frontend/src/index.css | 4 +-- frontend/src/lib/theme/colorTheme.test.ts | 27 +++++++++++++++++ frontend/src/lib/theme/colorTheme.ts | 25 ++++++++++++++-- shared/src/schemas/internal-assistant.ts | 1 + shared/src/schemas/settings.ts | 6 ++++ 9 files changed, 99 insertions(+), 5 deletions(-) diff --git a/backend/src/services/assistant-mode.ts b/backend/src/services/assistant-mode.ts index c0b34981..ef2fdb85 100644 --- a/backend/src/services/assistant-mode.ts +++ b/backend/src/services/assistant-mode.ts @@ -665,6 +665,7 @@ Retrieve the user's full settings, including all preferences. Stored credentials preferences: { theme: 'dark' | 'light' | 'system', colorTheme?: string, // one of: ${[MANAGER_COLOR_THEME_ID, ...OPENCODE_THEMES.map((theme) => theme.id)].join(', ')} + fontSize?: 'small' | 'medium' | 'large' | 'xlarge', mode: 'plan' | 'build', defaultModel?: string, defaultAgent?: string, diff --git a/frontend/index.html b/frontend/index.html index b8fc932e..cf4c38fb 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -26,6 +26,8 @@ (function () { try { var snapshot = JSON.parse(localStorage.getItem('ocm-appearance')); + var fontSize = localStorage.getItem('ocm-font-size'); + if (fontSize) document.documentElement.style.fontSize = fontSize; if (!snapshot) return; var root = document.documentElement; if (snapshot.dark) { diff --git a/frontend/src/components/settings/GeneralSettings.tsx b/frontend/src/components/settings/GeneralSettings.tsx index 3aa41ade..ac3e0093 100644 --- a/frontend/src/components/settings/GeneralSettings.tsx +++ b/frontend/src/components/settings/GeneralSettings.tsx @@ -4,6 +4,7 @@ import { MANAGER_COLOR_THEME_ID, OPENCODE_THEMES, isColorThemeId } from '@openco import { UserPreferencesSchema } from '@opencode-manager/shared/schemas' const themePreferenceSchema = UserPreferencesSchema.pick({ theme: true }) +const fontSizePreferenceSchema = UserPreferencesSchema.pick({ fontSize: true }) import { Loader2 } from 'lucide-react' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' @@ -106,6 +107,34 @@ export function GeneralSettings() { +
+
+ +

+ Scale text and spacing across the app +

+
+ +
+
diff --git a/frontend/src/contexts/ThemeContext.tsx b/frontend/src/contexts/ThemeContext.tsx index 068bf8b7..0a7699b2 100644 --- a/frontend/src/contexts/ThemeContext.tsx +++ b/frontend/src/contexts/ThemeContext.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' import { useSettings } from '@/hooks/useSettings' import { useAuth } from '@/hooks/useAuth' -import { applyColorTheme, getDocumentThemeMode, type ThemeMode } from '@/lib/theme/colorTheme' +import { applyColorTheme, applyFontSize, getDocumentThemeMode, type ThemeMode } from '@/lib/theme/colorTheme' import { ThemeContext } from './theme-context' export function ThemeProvider({ children }: { children: React.ReactNode }) { @@ -11,6 +11,13 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) { const hasPreferences = preferences !== undefined const theme = preferences?.theme || 'dark' const colorTheme = preferences?.colorTheme + const fontSize = preferences?.fontSize + + useEffect(() => { + if (!hasPreferences) return + + applyFontSize(document.documentElement, fontSize) + }, [hasPreferences, fontSize]) useEffect(() => { if (!hasPreferences) return diff --git a/frontend/src/index.css b/frontend/src/index.css index 5a079e85..d3fcf43c 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -403,12 +403,12 @@ body { input[type="url"], textarea, select { - font-size: 16px !important; + font-size: max(16px, 1rem) !important; } /* ContentEditable elements */ [contenteditable="true"] { - font-size: 16px !important; + font-size: max(16px, 1rem) !important; } } diff --git a/frontend/src/lib/theme/colorTheme.test.ts b/frontend/src/lib/theme/colorTheme.test.ts index 9f170ec1..2b5d3bd6 100644 --- a/frontend/src/lib/theme/colorTheme.test.ts +++ b/frontend/src/lib/theme/colorTheme.test.ts @@ -3,7 +3,9 @@ import { beforeEach, describe, expect, it } from 'vitest' import { APPEARANCE_STORAGE_KEY, AppearanceSnapshotSchema, + FONT_SIZE_STORAGE_KEY, applyColorTheme, + applyFontSize, readableTextColor, resolveColorThemeTokens, } from './colorTheme' @@ -148,3 +150,28 @@ describe('applyColorTheme', () => { expect(indexHtml).toContain(APPEARANCE_STORAGE_KEY) }) }) + +describe('applyFontSize', () => { + beforeEach(() => { + document.documentElement.removeAttribute('style') + window.localStorage.clear() + }) + + it('applies the scale to the root element and persists it for boot replay', () => { + applyFontSize(document.documentElement, 'large') + + expect(document.documentElement.style.fontSize).toBe('112.5%') + expect(window.localStorage.getItem(FONT_SIZE_STORAGE_KEY)).toBe('112.5%') + }) + + it('falls back to the default scale when no preference is set', () => { + applyFontSize(document.documentElement, undefined) + + expect(document.documentElement.style.fontSize).toBe('100%') + expect(window.localStorage.getItem(FONT_SIZE_STORAGE_KEY)).toBe('100%') + }) + + it('keeps the boot replay storage key in sync with index.html', () => { + expect(indexHtml).toContain(FONT_SIZE_STORAGE_KEY) + }) +}) diff --git a/frontend/src/lib/theme/colorTheme.ts b/frontend/src/lib/theme/colorTheme.ts index 4be5835f..fb9b9a2f 100644 --- a/frontend/src/lib/theme/colorTheme.ts +++ b/frontend/src/lib/theme/colorTheme.ts @@ -1,6 +1,7 @@ import { z } from 'zod' import { getOpenCodeTheme, MANAGER_COLOR_THEME_ID } from '@opencode-manager/shared/themes' import type { ColorThemeId, HexColor } from '@opencode-manager/shared/themes' +import type { FontSize } from '@opencode-manager/shared/schemas' const MANAGER_THEME_TOKENS = [ 'background', @@ -54,6 +55,15 @@ export type ThemeMode = 'light' | 'dark' export const APPEARANCE_STORAGE_KEY = 'ocm-appearance' +export const FONT_SIZE_STORAGE_KEY = 'ocm-font-size' + +const FONT_SIZE_SCALE: Record = { + small: '87.5%', + medium: '100%', + large: '112.5%', + xlarge: '125%', +} + export const AppearanceSnapshotSchema = z.object({ dark: z.boolean(), tokens: z.record(z.string(), z.string()).nullable(), @@ -165,14 +175,18 @@ export function resolveColorThemeTokens( } } -function persistAppearance(snapshot: AppearanceSnapshot): void { +function persistStorageValue(key: string, value: string): void { try { - window.localStorage.setItem(APPEARANCE_STORAGE_KEY, JSON.stringify(snapshot)) + window.localStorage.setItem(key, value) } catch { return } } +function persistAppearance(snapshot: AppearanceSnapshot): void { + persistStorageValue(APPEARANCE_STORAGE_KEY, JSON.stringify(snapshot)) +} + export function applyColorTheme( root: HTMLElement, colorTheme: ColorThemeId | undefined, @@ -196,3 +210,10 @@ export function applyColorTheme( persistAppearance({ dark: isDark, tokens: resolved, themeColor }) } + +export function applyFontSize(root: HTMLElement, fontSize: FontSize | undefined): void { + const scale = FONT_SIZE_SCALE[fontSize ?? 'medium'] + + root.style.fontSize = scale + persistStorageValue(FONT_SIZE_STORAGE_KEY, scale) +} diff --git a/shared/src/schemas/internal-assistant.ts b/shared/src/schemas/internal-assistant.ts index 23c183b5..e31a3d9d 100644 --- a/shared/src/schemas/internal-assistant.ts +++ b/shared/src/schemas/internal-assistant.ts @@ -102,6 +102,7 @@ export const AssistantSTTPatchSchema = z.object({ export const AssistantSettingsPatchSchema = UserPreferencesSchema.pick({ theme: true, colorTheme: true, + fontSize: true, mode: true, defaultModel: true, walkthroughModel: true, diff --git a/shared/src/schemas/settings.ts b/shared/src/schemas/settings.ts index ace5ff1b..a850f9d7 100644 --- a/shared/src/schemas/settings.ts +++ b/shared/src/schemas/settings.ts @@ -199,6 +199,10 @@ export const DEFAULT_SESSION_DEFAULTS = { permissionMode: 'ask', } satisfies SessionDefaults; +export const FontSizeSchema = z.enum(['small', 'medium', 'large', 'xlarge']); + +export type FontSize = z.infer; + export const DevicePairingPreferencesSchema = z.object({ allowPrivateNetworkHttp: z.boolean().optional(), }); @@ -208,6 +212,7 @@ export type DevicePairingPreferences = z.infer