mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-24 09:39:35 +02:00
[web] Avoid creating duplicate CM6 themes GitOrigin-RevId: f6132d6cdd94ef353e047ce229d89147acc89603
19 lines
557 B
TypeScript
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
|
|
}
|
|
}
|