Skip to content

Commit fedc0c6

Browse files
committed
Merge sprint-3/fix-editor-font — font picker now works
2 parents 1b88c1c + a47a076 commit fedc0c6

4 files changed

Lines changed: 19 additions & 10 deletions

File tree

apps/web/components/review-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useState } from "react"
44
import CodeMirror from "@uiw/react-codemirror"
5-
import { getThemeExtension, getFontCss, cleanGutter } from "@/lib/editor-prefs"
5+
import { getThemeExtension, getFontExtension, cleanGutter } from "@/lib/editor-prefs"
66
import { useEditorPrefs } from "@/hooks/use-editor-prefs"
77
import { cn } from "@/lib/utils"
88
import { getLanguageExtension, type Language } from "@/lib/languages"
@@ -96,6 +96,7 @@ export function ReviewCard({ snippet, index, total, onRate, submittingRating }:
9696
? [getLanguageExtension(snippet.language as Language)!]
9797
: []),
9898
cleanGutter,
99+
getFontExtension(prefs.font),
99100
]}
100101
editable={false}
101102
basicSetup={{
@@ -105,7 +106,6 @@ export function ReviewCard({ snippet, index, total, onRate, submittingRating }:
105106
autocompletion: false,
106107
}}
107108
className="text-sm"
108-
style={{ fontFamily: getFontCss(prefs.font) }}
109109
/>
110110
</div>
111111
</div>

apps/web/components/snippet-detail-client.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useRouter } from "next/navigation"
55
import { useAuth } from "@clerk/nextjs"
66
import { useQueryClient } from "@tanstack/react-query"
77
import CodeMirror from "@uiw/react-codemirror"
8-
import { getThemeExtension, getFontCss, cleanGutter } from "@/lib/editor-prefs"
8+
import { getThemeExtension, getFontExtension, cleanGutter } from "@/lib/editor-prefs"
99
import { useEditorPrefs } from "@/hooks/use-editor-prefs"
1010
import { EditorToolbar } from "@/components/editor-toolbar"
1111
import { HugeiconsIcon } from "@hugeicons/react"
@@ -253,6 +253,7 @@ function EditDialog({
253253
extensions={[
254254
...(getLanguageExtension(language) ? [getLanguageExtension(language)!] : []),
255255
cleanGutter,
256+
getFontExtension(prefs.font),
256257
]}
257258
basicSetup={{
258259
lineNumbers: true,
@@ -261,11 +262,7 @@ function EditDialog({
261262
autocompletion: false,
262263
}}
263264
className="text-sm"
264-
style={{
265-
fontFamily: getFontCss(prefs.font),
266-
maxHeight: "280px",
267-
overflowY: "auto",
268-
}}
265+
style={{ maxHeight: "280px", overflowY: "auto" }}
269266
/>
270267
</div>
271268
</div>

apps/web/components/snippet-editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useState } from "react"
44
import { useRouter } from "next/navigation"
55
import { useForm } from "@tanstack/react-form"
66
import CodeMirror from "@uiw/react-codemirror"
7-
import { getThemeExtension, getFontCss, cleanGutter } from "@/lib/editor-prefs"
7+
import { getThemeExtension, getFontExtension, cleanGutter } from "@/lib/editor-prefs"
88
import { useEditorPrefs } from "@/hooks/use-editor-prefs"
99
import { EditorToolbar } from "@/components/editor-toolbar"
1010
import { cn } from "@/lib/utils"
@@ -248,6 +248,7 @@ export function SnippetEditor() {
248248
? [getLanguageExtension(language as Language)!]
249249
: []),
250250
cleanGutter,
251+
getFontExtension(prefs.font),
251252
]}
252253
minHeight="240px"
253254
basicSetup={{
@@ -257,7 +258,6 @@ export function SnippetEditor() {
257258
autocompletion: true,
258259
}}
259260
className="text-sm"
260-
style={{ fontFamily: getFontCss(prefs.font) }}
261261
/>
262262
)}
263263
</form.Subscribe>

apps/web/lib/editor-prefs.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ export function getFontCss(font: EditorFont): string {
4747
return EDITOR_FONTS.find((f) => f.value === font)?.css ?? EDITOR_FONTS[0].css
4848
}
4949

50+
// CodeMirror sets font-family on .cm-scroller internally, so a wrapper style prop
51+
// has no effect. This extension targets the internal elements directly.
52+
export function getFontExtension(font: EditorFont): Extension {
53+
const family = getFontCss(font)
54+
return EditorView.theme({
55+
"&": { fontFamily: family },
56+
".cm-scroller": { fontFamily: family },
57+
".cm-content": { fontFamily: family },
58+
".cm-tooltip": { fontFamily: family },
59+
})
60+
}
61+
5062
// Cleans up the line-number gutter across all themes:
5163
// transparent background, subtle separator, tabular-nums, muted color.
5264
export const cleanGutter = EditorView.theme({

0 commit comments

Comments
 (0)