-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: terminal font dont always load #2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,6 +254,23 @@ async function downloadFont(name, link) { | |
| return FONT_FILE; | ||
| } | ||
|
|
||
| function injectFontFace(name) { | ||
| const $style = ensureStyleElement(FONT_FACE_STYLE_ID); | ||
| const css = get(name); | ||
|
|
||
| if (!css) return; | ||
|
|
||
| // Inject CSS if not already present (skip remote URL downloads - loadFont handles those) | ||
| if (!$style.textContent.includes(`font-family: '${name}'`)) { | ||
| $style.textContent = `${$style.textContent}\n${css}`; | ||
| } | ||
|
|
||
| // Kick off browser font loading without blocking | ||
| if (document.fonts?.load) { | ||
| document.fonts.load(`12px '${name}'`).catch(() => {}); | ||
| } | ||
| } | ||
|
Comment on lines
+257
to
+272
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For locally bundled fonts (like |
||
|
|
||
| async function loadFont(name) { | ||
| const $style = ensureStyleElement(FONT_FACE_STYLE_ID); | ||
| let css = get(name); | ||
|
|
@@ -279,6 +296,15 @@ async function loadFont(name) { | |
| $style.textContent = `${$style.textContent}\n${css}`; | ||
| } | ||
|
|
||
| // Ensure the browser has actually parsed and loaded the font | ||
| if (document.fonts?.load) { | ||
| try { | ||
| await document.fonts.load(`12px '${name}'`); | ||
| } catch { | ||
| // document.fonts.load may reject if font is unavailable | ||
| } | ||
| } | ||
|
|
||
| return css; | ||
| } | ||
|
|
||
|
|
@@ -303,4 +329,5 @@ export default { | |
| setEditorFont, | ||
| setAppFont, | ||
| loadFont, | ||
| injectFontFace, | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.