theme-cache.ts 557 B

123456789101112131415161718
  1. import { Extension } from '@codemirror/state'
  2. import { EditorView } from '@codemirror/view'
  3. export class ThemeCache {
  4. private cache: Map<string, Extension> = new Map()
  5. public get: typeof EditorView.theme = (styleMod, options) => {
  6. const key = JSON.stringify({ styleMod, options })
  7. const existing = this.cache.get(key)
  8. if (existing) {
  9. return existing
  10. }
  11. // eslint-disable-next-line @overleaf/no-generated-editor-themes
  12. const theme = EditorView.theme(styleMod, options)
  13. this.cache.set(key, theme)
  14. return theme
  15. }
  16. }