فهرست منبع

Merge pull request #27567 from overleaf/mj-ensure-theme-exists

[web] Ensure editor theme exists before loading it

GitOrigin-RevId: 771aafeda2d7dd3aae9656cdfbad75996a523ac8
Mathias Jakobsen 1 سال پیش
والد
کامیت
7e72af29ac
1فایلهای تغییر یافته به همراه9 افزوده شده و 0 حذف شده
  1. 9 0
      services/web/frontend/js/features/source-editor/extensions/theme.ts

+ 9 - 0
services/web/frontend/js/features/source-editor/extensions/theme.ts

@@ -6,6 +6,7 @@ import classNames from 'classnames'
 import { FontFamily, LineHeight, userStyles } from '@/shared/utils/styles'
 import { FontFamily, LineHeight, userStyles } from '@/shared/utils/styles'
 import { ActiveOverallTheme } from '@/shared/hooks/use-active-overall-theme'
 import { ActiveOverallTheme } from '@/shared/hooks/use-active-overall-theme'
 import { ThemeCache } from '../utils/theme-cache'
 import { ThemeCache } from '../utils/theme-cache'
+import getMeta from '@/utils/meta'
 
 
 const optionsThemeConf = new Compartment()
 const optionsThemeConf = new Compartment()
 const selectedThemeConf = new Compartment()
 const selectedThemeConf = new Compartment()
@@ -277,6 +278,14 @@ const loadSelectedTheme = async (editorTheme: string) => {
   }
   }
 
 
   if (!themeCache.has(editorTheme)) {
   if (!themeCache.has(editorTheme)) {
+    const themes = getMeta('ol-editorThemes') || []
+    const legacyThemes = getMeta('ol-legacyEditorThemes') || []
+    const themeExists =
+      themes.includes(editorTheme) || legacyThemes.includes(editorTheme)
+    if (!themeExists) {
+      editorTheme = 'textmate' // fallback to default if the theme is not found
+    }
+
     const { theme, highlightStyle, dark } = await import(
     const { theme, highlightStyle, dark } = await import(
       /* webpackChunkName: "cm6-theme" */ `../themes/cm6/${editorTheme}.json`
       /* webpackChunkName: "cm6-theme" */ `../themes/cm6/${editorTheme}.json`
     )
     )