Skip to content

Commit 824a0f4

Browse files
committed
perf(web): validate monospace fonts when selected
1 parent 4ee6bfd commit 824a0f4

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ComboboxTrigger,
1313
} from "../ui/combobox";
1414
import { SelectButton } from "../ui/select";
15+
import { stackedThreadToast, toastManager } from "../ui/toast";
1516

1617
const DEFAULT_FONT_VALUE = "__default__";
1718

@@ -141,8 +142,8 @@ export function FontFamilyPicker({
141142

142143
const families = useMemo(() => {
143144
if (enumeration.status !== "granted") return [];
144-
return requireMonospace ? enumeration.families.filter(isMonospaceFamily) : enumeration.families;
145-
}, [enumeration, requireMonospace]);
145+
return enumeration.families;
146+
}, [enumeration]);
146147

147148
const items = useMemo(() => {
148149
const trimmedQuery = query.trim().toLowerCase();
@@ -160,6 +161,16 @@ export function FontFamilyPicker({
160161

161162
const handlePick = (value: string) => {
162163
setOpen(false);
164+
if (value !== DEFAULT_FONT_VALUE && requireMonospace && !isMonospaceFamily(value)) {
165+
toastManager.add(
166+
stackedThreadToast({
167+
type: "error",
168+
title: `"${value}" isn't monospace`,
169+
description: "Code and terminal need a fixed-width font, so the current font was kept.",
170+
}),
171+
);
172+
return;
173+
}
163174
onSelect(value === DEFAULT_FONT_VALUE ? "" : value);
164175
};
165176

0 commit comments

Comments
 (0)