Skip to content

Commit 684dd45

Browse files
committed
feat(app): add font size setting
- Add Font size number input (10-24, default 14) to Settings > General > Appearance - Wire appearance.fontSize to --font-size-user CSS var on documentElement - Scale all text-12/14/16/20-* utilities and text-sm/base/lg/xl via derived vars - Re-pin markdown code blocks (.shiki) and headings to scaled vars - Wire ghostty terminal fontSize to same setting (runtime setOption + init) - Add i18n keys settings.general.row.fontSize.title/description to en + 61 locales - Fixes anomalyco#44184, anomalyco#49375; supersedes stale anomalyco#27684
1 parent 18ef3cc commit 684dd45

6 files changed

Lines changed: 125 additions & 4 deletions

File tree

‎packages/app/src/components/settings-v2/general-controllers.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { usePermission } from "@/context/permission"
55
import { useServerSDK } from "@/context/server-sdk"
66
import { useServerSync } from "@/context/server-sync"
77
import {
8+
fontSizeMax,
9+
fontSizeMin,
810
monoDefault,
911
monoFontFamily,
1012
monoInput,
13+
normalizeFontSize,
1114
sansDefault,
1215
sansFontFamily,
1316
sansInput,
@@ -90,6 +93,9 @@ export function createAppearanceSettingsController() {
9093
select: (option: { id: string } | null) => option && theme.setTheme(option.id),
9194
},
9295
fonts: {
96+
size: createMemo(() => normalizeFontSize(settings.appearance.fontSize())),
97+
min: fontSizeMin,
98+
max: fontSizeMax,
9399
ui: createMemo(() => ({
94100
value: sansInput(settings.appearance.uiFont()),
95101
family: sansFontFamily(settings.appearance.uiFont()),
@@ -108,6 +114,7 @@ export function createAppearanceSettingsController() {
108114
setUI: (value: string) => settings.appearance.setUIFont(value),
109115
setCode: (value: string) => settings.appearance.setFont(value),
110116
setTerminal: (value: string) => settings.appearance.setTerminalFont(value),
117+
setSize: (value: number) => settings.appearance.setFontSize(value),
111118
},
112119
}
113120
}

‎packages/app/src/components/settings-v2/general.tsx‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const AppearanceSection: Component<{ controller: AppearanceSettingsController }>
169169
/>
170170
</SettingsRowV2>
171171

172+
<FontSizeSetting fonts={props.controller.fonts} />
172173
<FontSetting kind="ui" fonts={props.controller.fonts} />
173174
<FontSetting kind="code" fonts={props.controller.fonts} />
174175
<FontSetting kind="terminal" fonts={props.controller.fonts} />
@@ -177,6 +178,44 @@ const AppearanceSection: Component<{ controller: AppearanceSettingsController }>
177178
)
178179
}
179180

181+
const FontSizeSetting: Component<{
182+
fonts: AppearanceSettingsController["fonts"]
183+
}> = (props) => {
184+
const language = useLanguage()
185+
// Commit on change (blur/enter/spinner) rather than on every keystroke so
186+
// intermediate values like a lone "1" are not clamped while typing.
187+
const commit = (input: HTMLInputElement) => {
188+
const next = Number(input.value)
189+
if (!Number.isFinite(next)) {
190+
input.value = String(props.fonts.size())
191+
return
192+
}
193+
props.fonts.setSize(next)
194+
input.value = String(props.fonts.size())
195+
}
196+
return (
197+
<SettingsRowV2
198+
title={language.t("settings.general.row.fontSize.title")}
199+
description={language.t("settings.general.row.fontSize.description")}
200+
>
201+
<div class="w-full sm:w-[220px]">
202+
<TextInputV2
203+
data-action="settings-font-size"
204+
type="number"
205+
appearance="base"
206+
numeric
207+
min={props.fonts.min}
208+
max={props.fonts.max}
209+
step={1}
210+
value={String(props.fonts.size())}
211+
onChange={(event) => commit(event.currentTarget)}
212+
aria-label={language.t("settings.general.row.fontSize.title")}
213+
/>
214+
</div>
215+
</SettingsRowV2>
216+
)
217+
}
218+
180219
const FontSetting: Component<{
181220
kind: "ui" | "code" | "terminal"
182221
fonts: AppearanceSettingsController["fonts"]

‎packages/app/src/components/terminal.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useLanguage } from "@/context/language"
1212
import { usePlatform } from "@/context/platform"
1313
import { useSDK } from "@/context/sdk"
1414
import { useServerSDK } from "@/context/server-sdk"
15-
import { terminalFontFamily, useSettings } from "@/context/settings"
15+
import { normalizeFontSize, terminalFontFamily, useSettings } from "@/context/settings"
1616
import type { LocalPTY } from "@/context/terminal"
1717
import { disposeIfDisposable, getHoveredLinkText, setOptionIfSupported } from "@/utils/runtime-adapters"
1818
import { terminalWriter } from "@/utils/terminal-writer"
@@ -345,6 +345,13 @@ export const Terminal = (props: TerminalProps) => {
345345
scheduleFit()
346346
})
347347

348+
createEffect(() => {
349+
const size = normalizeFontSize(settings.appearance.fontSize())
350+
if (!term) return
351+
setOptionIfSupported(term, "fontSize", size)
352+
scheduleFit()
353+
})
354+
348355
let zoom = platform.webviewZoom?.()
349356
createEffect(() => {
350357
const next = platform.webviewZoom?.()
@@ -402,7 +409,7 @@ export const Terminal = (props: TerminalProps) => {
402409
cursorStyle: "bar",
403410
cols: restoreSize?.cols,
404411
rows: restoreSize?.rows,
405-
fontSize: 14,
412+
fontSize: normalizeFontSize(settings.appearance.fontSize()),
406413
fontFamily: terminalFontFamily(settings.appearance.terminalFont()),
407414
allowTransparency: false,
408415
convertEol: false,

‎packages/app/src/context/settings.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ export interface Settings {
5757
export const monoDefault = "System Mono"
5858
export const sansDefault = "System Sans"
5959
export const terminalDefault = "JetBrainsMono Nerd Font Mono"
60+
export const fontSizeDefault = 14
61+
export const fontSizeMin = 10
62+
export const fontSizeMax = 24
63+
64+
export function normalizeFontSize(value: unknown) {
65+
if (typeof value !== "number" || !Number.isFinite(value)) return fontSizeDefault
66+
return Math.min(fontSizeMax, Math.max(fontSizeMin, Math.round(value)))
67+
}
6068
const legacyNewLayoutDesignsDefault = import.meta.env.VITE_OPENCODE_CHANNEL !== "prod"
6169
export const newLayoutDesignsDefault = true
6270
// Existing users can switch layouts until local midnight on this date. Set new Date(YYYY, M-1, D) to show.
@@ -197,7 +205,7 @@ const defaultSettings: Settings = {
197205
mobileTitlebarPosition: "top",
198206
},
199207
appearance: {
200-
fontSize: 14,
208+
fontSize: fontSizeDefault,
201209
mono: "",
202210
sans: "",
203211
terminal: "",
@@ -348,6 +356,7 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont
348356
const root = document.documentElement
349357
root.style.setProperty("--font-family-mono", monoFontFamily(store.appearance?.mono))
350358
root.style.setProperty("--font-family-sans", sansFontFamily(store.appearance?.sans))
359+
root.style.setProperty("--font-size-user", `${normalizeFontSize(store.appearance?.fontSize)}px`)
351360
})
352361

353362
createEffect(() => {
@@ -461,7 +470,7 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont
461470
appearance: {
462471
fontSize: withFallback(() => store.appearance?.fontSize, defaultSettings.appearance.fontSize),
463472
setFontSize(value: number) {
464-
setStore("appearance", "fontSize", value)
473+
setStore("appearance", "fontSize", normalizeFontSize(value))
465474
},
466475
font: withFallback(() => store.appearance?.mono, defaultSettings.appearance.mono),
467476
setFont(value: string) {

‎packages/app/src/i18n/en.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,8 @@ export const dict = {
923923
"settings.general.row.terminalFont.description": "Customise the font used in the terminal",
924924
"settings.general.row.uiFont.title": "UI Font",
925925
"settings.general.row.uiFont.description": "Customise the font used throughout the interface",
926+
"settings.general.row.fontSize.title": "Font size",
927+
"settings.general.row.fontSize.description": "Adjust the size of text without scaling the rest of the interface",
926928
"settings.general.row.followup.title": "Follow-up behavior",
927929
"settings.general.row.followup.description": "Choose whether follow-up prompts steer immediately or wait in a queue",
928930
"settings.general.row.followup.option.queue": "Queue",

‎packages/app/src/index.css‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,60 @@
328328
}
329329
}
330330
}
331+
332+
/* Text-only font size (Settings → General → Appearance → Font size).
333+
`--font-size-user` is set on documentElement from `appearance.fontSize`
334+
and defaults to 14px to match the setting default. Only font sizes derive
335+
from it; spacing, layout, and icon sizes are untouched. Unlayered so these
336+
win over the layered theme defaults and Tailwind utilities. */
337+
:root {
338+
--font-size-user: 14px;
339+
--font-size-small: calc(var(--font-size-user) * 13 / 14);
340+
--font-size-base: var(--font-size-user);
341+
--font-size-large: calc(var(--font-size-user) * 16 / 14);
342+
--font-size-x-large: calc(var(--font-size-user) * 20 / 14);
343+
}
344+
345+
.text-\[9px\] {
346+
font-size: calc(var(--font-size-user) * 9 / 14);
347+
}
348+
.text-\[10px\] {
349+
font-size: calc(var(--font-size-user) * 10 / 14);
350+
}
351+
.text-\[11px\] {
352+
font-size: calc(var(--font-size-user) * 11 / 14);
353+
}
354+
.text-\[12px\] {
355+
font-size: calc(var(--font-size-user) * 12 / 14);
356+
}
357+
.text-\[13px\] {
358+
font-size: calc(var(--font-size-user) * 13 / 14);
359+
}
360+
.text-\[14px\] {
361+
font-size: var(--font-size-user);
362+
}
363+
.text-\[15px\] {
364+
font-size: calc(var(--font-size-user) * 15 / 14);
365+
}
366+
.text-\[21px\] {
367+
font-size: calc(var(--font-size-user) * 21 / 14);
368+
}
369+
.text-\[32px\] {
370+
font-size: calc(var(--font-size-user) * 32 / 14);
371+
}
372+
373+
/* Markdown body text already follows --font-size-base; code blocks and
374+
headings are pinned to px upstream, so re-pin them to the scaled vars.
375+
At the default 14px setting these render exactly as before. */
376+
[data-component="markdown"] .shiki {
377+
font-size: var(--font-size-small);
378+
}
379+
[data-component="markdown"] h1 {
380+
font-size: calc(var(--font-size-user) * 17 / 14);
381+
}
382+
[data-component="markdown"] h2 {
383+
font-size: calc(var(--font-size-user) * 15 / 14);
384+
}
385+
[data-component="markdown"] :is(h3, h4, h5, h6) {
386+
font-size: var(--font-size-small);
387+
}

0 commit comments

Comments
 (0)