Files
overleaf-cep/services/web/frontend/js/features/source-editor/utils/theme-cache.ts
Mathias Jakobsen d8f18f9667 Merge pull request #27099 from overleaf/mj-no-duplicate-themes
[web] Avoid creating duplicate CM6 themes

GitOrigin-RevId: f6132d6cdd94ef353e047ce229d89147acc89603
2025-08-05 08:05:14 +00:00

19 lines
557 B
TypeScript

import { Extension } from '@codemirror/state'
import { EditorView } from '@codemirror/view'
export class ThemeCache {
private cache: Map<string, Extension> = new Map()
public get: typeof EditorView.theme = (styleMod, options) => {
const key = JSON.stringify({ styleMod, options })
const existing = this.cache.get(key)
if (existing) {
return existing
}
// eslint-disable-next-line @overleaf/no-generated-editor-themes
const theme = EditorView.theme(styleMod, options)
this.cache.set(key, theme)
return theme
}
}