From fa2dec724a81473f7fbbe220d563bb1cb0182192 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 6 Apr 2021 06:56:35 +0300 Subject: [PATCH] fix editor theme in FF containers, fixes #1222 --- edit/base.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/edit/base.js b/edit/base.js index a7f3af97..f44686d2 100644 --- a/edit/base.js +++ b/edit/base.js @@ -95,13 +95,18 @@ const baseInit = (() => { /** Preloads the theme so CodeMirror can use the correct metrics in its first render */ async function loadTheme() { const theme = prefs.get('editor.theme'); + if (!CODEMIRROR_THEMES.includes(theme)) { + prefs.set('editor.theme', 'default'); + return; + } if (theme !== 'default') { const el = $('#cm-theme'); const el2 = await require([`/vendor/codemirror/theme/${theme}.css`]); el2.id = el.id; el.remove(); - if (!el2.sheet) { - prefs.set('editor.theme', 'default'); + // FF containers take more time to load CSS + for (let retry = 0; !el2.sheet && ++retry <= 10;) { + await new Promise(requestAnimationFrame); } } }