Skip to content

Commit f7743d0

Browse files
committed
fix: Fonts do not persist after restart(#838)
1 parent a811002 commit f7743d0

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/lib/fonts.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,23 @@ async function setFont(name) {
150150
);
151151
let css = get(name);
152152

153-
// get all url font css
154-
const urls = /url\((.*?)\)/g.exec(css)?.slice(1);
155-
156-
await Promise.all(
157-
urls?.map(async (url) => {
158-
if (!/^https?/.test(url)) return;
159-
if (/^https?:\/\/localhost/) return;
160-
const fontFile = await downloadFont(name, url);
161-
const internalUrl = await helpers.toInternalUri(fontFile);
162-
css = css.replace(url, internalUrl);
163-
}),
164-
);
165-
166-
$style.textContent = `${css}
153+
// Get all URL font references
154+
const urls = [...css.matchAll(/url\((.*?)\)/g)].map((match) => match[1]);
155+
156+
urls?.map(async (url) => {
157+
if (!/^https?/.test(url)) return;
158+
if (/^https?:\/\/localhost/.test(url)) return;
159+
const fontFile = await downloadFont(name, url);
160+
const internalUrl = await helpers.toInternalUri(fontFile);
161+
css = css.replace(url, internalUrl);
162+
}),
163+
($style.textContent = `${css}
167164
.editor-container.ace_editor{
168165
font-family: "${name}", NotoMono, Monaco, MONOSPACE !important;
169166
}
170167
.ace_text{
171168
font-family: inherit !important;
172-
}`;
169+
}`);
173170
document.head.append($style);
174171
} catch (error) {
175172
toast(`${name} font not found`, "error");
@@ -191,6 +188,7 @@ async function downloadFont(name, link) {
191188
}
192189

193190
const font = await fsOperation(link).readFile();
191+
console.log("fonts content : ", font);
194192
await fsOperation(FONT_DIR).createFile(name, font);
195193

196194
return FONT_FILE;

0 commit comments

Comments
 (0)