@@ -5,13 +5,14 @@ import { ThemeMode } from '@renderer/types'
55import { ReactCodeMirrorProps } from '@uiw/react-codemirror'
66import type React from 'react'
77import { createContext , type PropsWithChildren , use , useCallback , useEffect , useMemo , useState } from 'react'
8+ import * as cmThemes from '@uiw/codemirror-themes-all'
89
910interface CodeStyleContextType {
1011 highlightCodeChunk : ( trunk : string , language : string , callerId : string ) => Promise < HighlightChunkResult >
1112 cleanupTokenizers : ( callerId : string ) => void
1213 getShikiPreProperties : ( language : string ) => Promise < ShikiPreProperties >
1314 themeNames : string [ ]
14- activeCmTheme : ReactCodeMirrorProps [ 'theme' ] | null
15+ activeCmTheme : any
1516 languageMap : Record < string , string >
1617}
1718
@@ -28,16 +29,11 @@ const CodeStyleContext = createContext<CodeStyleContextType>(defaultCodeStyleCon
2829
2930export const CodeStyleProvider : React . FC < PropsWithChildren > = ( { children } ) => {
3031 const { codeEditor, codeStyle, theme } = useSettings ( )
31- const [ cmThemes , setCmThemes ] = useState ( { } )
3232 const [ shikiThemes , setShikiThemes ] = useState ( { } )
3333 useMermaid ( )
3434
3535 useEffect ( ( ) => {
36- if ( codeEditor . enabled ) {
37- import ( '@uiw/codemirror-themes-all' ) . then ( ( themes ) => {
38- setCmThemes ( themes )
39- } )
40- } else {
36+ if ( ! codeEditor . enabled ) {
4137 import ( 'shiki' ) . then ( ( { bundledThemes } ) => {
4238 setShikiThemes ( bundledThemes )
4339 } )
@@ -75,9 +71,8 @@ export const CodeStyleProvider: React.FC<PropsWithChildren> = ({ children }) =>
7571 const activeCmTheme = useMemo ( ( ) => {
7672 if ( ! codeEditor . enabled ) return null
7773
78- const _cmTheme = activeThemeName as ReactCodeMirrorProps [ 'theme' ]
79- return cmThemes [ _cmTheme as keyof typeof cmThemes ] || _cmTheme
80- } , [ activeThemeName , cmThemes , codeEditor . enabled ] )
74+ return cmThemes [ activeThemeName as keyof typeof cmThemes ] || activeThemeName
75+ } , [ activeThemeName , codeEditor . enabled ] )
8176
8277 // 一些语言的别名
8378 const languageMap = useMemo ( ( ) => {
0 commit comments