Merge pull request #27099 from overleaf/mj-no-duplicate-themes
[web] Avoid creating duplicate CM6 themes GitOrigin-RevId: f6132d6cdd94ef353e047ce229d89147acc89603
This commit is contained in:
committed by
Copybot
parent
12586765fb
commit
d8f18f9667
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user