Skip to content

Commit cddcab2

Browse files
fionn77claude
andcommitted
feat(web): add a chat font size setting
Conversation text can now be sized independently of the interface. The setting follows the interface size by default; an explicit size rescales the text tokens inside timeline rows, leaving chrome, the prompt and code at their own sizes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d53873b commit cddcab2

11 files changed

Lines changed: 136 additions & 5 deletions

File tree

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const clientSettings: ClientSettings = {
4545
fontFamilyComposer: "",
4646
fontFamilySans: "",
4747
fontFamilyTerminal: "",
48+
fontSizeChat: null,
4849
fontSizeCode: 13,
4950
fontSizeInterface: 16,
5051
fontSizePrompt: 14,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { chatFontScale } from "./appearanceFonts";
4+
5+
describe("chatFontScale", () => {
6+
it("follows the interface when unset or equal to it", () => {
7+
expect(chatFontScale(null, 16)).toBeNull();
8+
expect(chatFontScale(16, 16)).toBeNull();
9+
});
10+
11+
it("scales chat text relative to the interface size", () => {
12+
expect(chatFontScale(20, 16)).toBe(1.25);
13+
expect(chatFontScale(12, 16)).toBe(0.75);
14+
expect(chatFontScale(18, 12)).toBe(1.5);
15+
});
16+
17+
it("clamps out-of-range sizes before scaling", () => {
18+
expect(chatFontScale(40, 16)).toBe(20 / 16);
19+
expect(chatFontScale(20, 40)).toBeNull();
20+
});
21+
});

‎apps/web/src/appearanceFonts.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface AppearanceFontPreferences {
6464
readonly code: string;
6565
readonly composer: string;
6666
readonly sizeInterface: number;
67+
readonly sizeChat: number | null;
6768
readonly sizePrompt: number;
6869
readonly sizeCode: number;
6970
readonly smoothing: boolean;
@@ -93,6 +94,12 @@ export function applyAppearanceFontVariables(
9394
}
9495

9596
root.style.fontSize = `${clampInterfaceFontSize(preferences.sizeInterface)}px`;
97+
const chatScale = chatFontScale(preferences.sizeChat, preferences.sizeInterface);
98+
if (chatScale === null) {
99+
root.style.removeProperty("--chat-font-size-ratio");
100+
} else {
101+
root.style.setProperty("--chat-font-size-ratio", String(chatScale));
102+
}
96103
root.style.setProperty("--font-size-prompt", `${clampPromptFontSize(preferences.sizePrompt)}px`);
97104
const code = clampCodeFontSize(preferences.sizeCode);
98105
root.style.setProperty("--font-size-code", `${code}px`);
@@ -119,6 +126,18 @@ function clampInterfaceFontSize(value: number): number {
119126
);
120127
}
121128

129+
/**
130+
* Chat text keeps its rem-based sizes, so a chat size is applied as a ratio to
131+
* the interface size rather than as pixels. Null means chat follows the
132+
* interface.
133+
*/
134+
export function chatFontScale(sizeChat: number | null, sizeInterface: number): number | null {
135+
if (sizeChat === null) return null;
136+
const chat = clampInterfaceFontSize(sizeChat);
137+
const base = clampInterfaceFontSize(sizeInterface);
138+
return chat === base ? null : chat / base;
139+
}
140+
122141
function clampPromptFontSize(value: number): number {
123142
return clampFontSize(value, MIN_PROMPT_FONT_SIZE, MAX_PROMPT_FONT_SIZE, DEFAULT_PROMPT_FONT_SIZE);
124143
}

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
10461046
<TimelineRowCtx value={sharedState}>
10471047
<div className="messages-timeline-row-frame">
10481048
<div
1049-
className="@container/chat-lane chat-content-lane overflow-x-clip"
1049+
className="@container/chat-lane chat-content-lane chat-text-scope overflow-x-clip"
10501050
data-timeline-root="true"
10511051
>
10521052
<TimelineRowContent row={item} />

‎apps/web/src/components/settings/SettingsPanels.logic.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type TypographySettings = Pick<
7979
| "fontFamilyCode"
8080
| "fontFamilyTerminal"
8181
| "fontSizeInterface"
82+
| "fontSizeChat"
8283
| "fontSizePrompt"
8384
| "fontSizeCode"
8485
| "fontSizeTerminal"
@@ -90,6 +91,7 @@ export function getChangedTypographySettingLabels(settings: TypographySettings):
9091
settings.fontSizeInterface !== DEFAULT_UNIFIED_SETTINGS.fontSizeInterface
9192
? ["Interface font"]
9293
: []),
94+
...(settings.fontSizeChat !== DEFAULT_UNIFIED_SETTINGS.fontSizeChat ? ["Chat font size"] : []),
9395
...(settings.fontFamilyComposer !== DEFAULT_UNIFIED_SETTINGS.fontFamilyComposer ||
9496
settings.fontSizePrompt !== DEFAULT_UNIFIED_SETTINGS.fontSizePrompt
9597
? ["Prompt font"]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ export function useSettingsRestore(onRestored?: () => void) {
635635
fontFamilyCode: DEFAULT_UNIFIED_SETTINGS.fontFamilyCode,
636636
fontFamilyTerminal: DEFAULT_UNIFIED_SETTINGS.fontFamilyTerminal,
637637
fontSizeInterface: DEFAULT_UNIFIED_SETTINGS.fontSizeInterface,
638+
fontSizeChat: DEFAULT_UNIFIED_SETTINGS.fontSizeChat,
638639
fontSizePrompt: DEFAULT_UNIFIED_SETTINGS.fontSizePrompt,
639640
fontSizeCode: DEFAULT_UNIFIED_SETTINGS.fontSizeCode,
640641
fontSizeTerminal: DEFAULT_UNIFIED_SETTINGS.fontSizeTerminal,

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,64 @@ function InterfaceFontRow({ preview }: { preview?: ReactNode }) {
8282
);
8383
}
8484

85+
const FOLLOW_INTERFACE_VALUE = "interface";
86+
87+
function ChatFontSizeRow() {
88+
const settings = useScopedSettings();
89+
const updateSettings = useUpdateScopedSettings();
90+
const value = settings.fontSizeChat;
91+
return (
92+
<SettingsRow
93+
{...searchableSetting("chat-font-size")}
94+
description="Your messages and the agent's replies. Follows the interface size by default."
95+
resetAction={
96+
value !== DEFAULT_UNIFIED_SETTINGS.fontSizeChat ? (
97+
<SettingResetButton
98+
label="chat font size"
99+
onClick={() => updateSettings({ fontSizeChat: DEFAULT_UNIFIED_SETTINGS.fontSizeChat })}
100+
/>
101+
) : null
102+
}
103+
control={
104+
<Select
105+
value={value === null ? FOLLOW_INTERFACE_VALUE : String(value)}
106+
onValueChange={(next) => {
107+
if (next === FOLLOW_INTERFACE_VALUE) {
108+
updateSettings({ fontSizeChat: null });
109+
return;
110+
}
111+
const parsed = Number(next);
112+
if (
113+
Number.isInteger(parsed) &&
114+
parsed >= MIN_INTERFACE_FONT_SIZE &&
115+
parsed <= MAX_INTERFACE_FONT_SIZE
116+
) {
117+
updateSettings({ fontSizeChat: parsed });
118+
}
119+
}}
120+
>
121+
<SelectTrigger size="sm" className="w-28 shrink-0" aria-label="Chat font size">
122+
<SelectValue>{value === null ? "Interface" : `${value} px`}</SelectValue>
123+
</SelectTrigger>
124+
<SelectPopup align="end" alignItemWithTrigger={false}>
125+
<SelectItem hideIndicator value={FOLLOW_INTERFACE_VALUE}>
126+
Interface
127+
</SelectItem>
128+
{Array.from(
129+
{ length: MAX_INTERFACE_FONT_SIZE - MIN_INTERFACE_FONT_SIZE + 1 },
130+
(_, index) => MIN_INTERFACE_FONT_SIZE + index,
131+
).map((px) => (
132+
<SelectItem hideIndicator key={px} value={String(px)}>
133+
{px} px
134+
</SelectItem>
135+
))}
136+
</SelectPopup>
137+
</Select>
138+
}
139+
/>
140+
);
141+
}
142+
85143
function PromptFontRow() {
86144
const settings = useScopedSettings();
87145
const updateSettings = useUpdateScopedSettings();
@@ -254,6 +312,7 @@ function FontSettingsGroup() {
254312
return (
255313
<>
256314
<InterfaceFontRow />
315+
<ChatFontSizeRow />
257316
<PromptFontRow />
258317
<CodeFontRow />
259318
<TerminalFontRow />
@@ -267,6 +326,7 @@ function SimpleFontRows() {
267326
return (
268327
<>
269328
<InterfaceFontRow preview={<PromptFontPreview />} />
329+
<ChatFontSizeRow />
270330
<CodeFontRow
271331
title="Monospace font"
272332
description="Code blocks, diffs, file previews, and the terminal."

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ export const SETTINGS_SEARCH_ITEMS = [
285285
to: "/settings/appearance",
286286
searchTerms: ["typography family size system sans"],
287287
},
288+
{
289+
id: "chat-font-size",
290+
title: "Chat font size",
291+
to: "/settings/appearance",
292+
searchTerms: ["typography text size conversation messages replies responses timeline"],
293+
},
288294
{
289295
id: "prompt-font",
290296
title: "Prompt font",

‎apps/web/src/index.css‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,19 @@ code {
17841784
background: var(--app-scrollbar-thumb-hover);
17851785
}
17861786

1787+
/* Chat font size. Tailwind's text utilities read these tokens, so rescaling
1788+
them here resizes conversation text without touching chrome, the prompt, or
1789+
code, which sizes itself in pixels through --font-size-code. The root only
1790+
carries the ratio; scaling applies inside the scope, so markdown elsewhere
1791+
(prompt, file previews) keeps the interface size. */
1792+
.chat-text-scope {
1793+
--chat-font-scale: var(--chat-font-size-ratio, 1);
1794+
--text-xs: calc(0.75rem * var(--chat-font-scale, 1));
1795+
--text-sm: calc(0.875rem * var(--chat-font-scale, 1));
1796+
--text-base: calc(1rem * var(--chat-font-scale, 1));
1797+
--text-lg: calc(1.125rem * var(--chat-font-scale, 1));
1798+
}
1799+
17871800
/* Chat markdown rendering */
17881801

17891802
.chat-markdown > :first-child {
@@ -1822,21 +1835,21 @@ code {
18221835
}
18231836

18241837
:is(.chat-markdown, .composer-tiptap) h1 {
1825-
font-size: 1.25rem;
1838+
font-size: calc(1.25rem * var(--chat-font-scale, 1));
18261839
}
18271840

18281841
:is(.chat-markdown, .composer-tiptap) h2 {
1829-
font-size: 1.125rem;
1842+
font-size: calc(1.125rem * var(--chat-font-scale, 1));
18301843
}
18311844

18321845
:is(.chat-markdown, .composer-tiptap) h3 {
1833-
font-size: 1rem;
1846+
font-size: calc(1rem * var(--chat-font-scale, 1));
18341847
}
18351848

18361849
:is(.chat-markdown, .composer-tiptap) h4,
18371850
:is(.chat-markdown, .composer-tiptap) h5,
18381851
:is(.chat-markdown, .composer-tiptap) h6 {
1839-
font-size: 0.875rem;
1852+
font-size: calc(0.875rem * var(--chat-font-scale, 1));
18401853
}
18411854

18421855
:is(.chat-markdown, .composer-tiptap) h6 {

‎apps/web/src/routes/__root.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ function FontAppearanceSync() {
313313
const fontFamilyCode = useClientSettings((settings) => settings.fontFamilyCode);
314314
const fontFamilyComposer = useClientSettings((settings) => settings.fontFamilyComposer);
315315
const fontSizeInterface = useClientSettings((settings) => settings.fontSizeInterface);
316+
const fontSizeChat = useClientSettings((settings) => settings.fontSizeChat);
316317
const fontSizePrompt = useClientSettings((settings) => settings.fontSizePrompt);
317318
const fontSizeCode = useClientSettings((settings) => settings.fontSizeCode);
318319
const fontSmoothing = useClientSettings((settings) => settings.fontSmoothing);
@@ -323,6 +324,7 @@ function FontAppearanceSync() {
323324
code: fontFamilyCode,
324325
composer: fontFamilyComposer,
325326
sizeInterface: fontSizeInterface,
327+
sizeChat: fontSizeChat,
326328
sizePrompt: fontSizePrompt,
327329
sizeCode: fontSizeCode,
328330
smoothing: fontSmoothing,
@@ -332,6 +334,7 @@ function FontAppearanceSync() {
332334
fontFamilyComposer,
333335
fontFamilySans,
334336
fontSizeCode,
337+
fontSizeChat,
335338
fontSizeInterface,
336339
fontSizePrompt,
337340
fontSmoothing,

0 commit comments

Comments
 (0)