Merge pull request #27099 from overleaf/mj-no-duplicate-themes

[web] Avoid creating duplicate CM6 themes

GitOrigin-RevId: f6132d6cdd94ef353e047ce229d89147acc89603
This commit is contained in:
Mathias Jakobsen
2025-08-05 08:05:14 +00:00
committed by Copybot
parent 12586765fb
commit d8f18f9667
5 changed files with 40 additions and 14 deletions
@@ -0,0 +1,18 @@
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
}
}