@@ -5,15 +5,22 @@ import { EditorView } from "@codemirror/view";
55import { syntaxHighlighting , HighlightStyle } from "@codemirror/language" ;
66const toObject = ( value , fallback = { } ) => value ?? fallback ;
77const userSettings = toObject ( MarkEdit . userSettings ) ;
8- const rootValue = toObject ( userSettings [ "extension.markeditTheming" ] ) ;
9- const enabledMode = rootValue . enabledMode ?? "both" ;
10- const lightColors = toObject ( rootValue . lightTheme ) ;
11- const darkColors = toObject ( rootValue . darkTheme ) ;
12- const isModeCustomized = ( isDark ) => [ "both" , isDark ? "dark" : "light" ] . includes ( enabledMode ) ;
8+ const rootValue = settingsForKey ( "extension.markeditTheming" ) ;
9+ const lightColors = isModeEnabled ( false ) ? toObject ( rootValue . lightTheme ) : void 0 ;
10+ const darkColors = isModeEnabled ( true ) ? toObject ( rootValue . darkTheme ) : void 0 ;
11+ function settingsForKey ( key ) {
12+ return key === void 0 ? { } : toObject ( userSettings [ key ] ) ;
13+ }
14+ function enabledMode ( settings ) {
15+ return settings . enabledMode ?? "both" ;
16+ }
17+ function isModeEnabled ( isDark , mode = enabledMode ( rootValue ) ) {
18+ return [ "both" , isDark ? "dark" : "light" ] . includes ( mode ) ;
19+ }
1320function buildBlendedTheme ( isDark , extension , colors ) {
1421 const mergedColors = mergeColors ( {
1522 lhs : colors ,
16- rhs : isModeCustomized ( isDark ) ? isDark ? darkColors : lightColors : void 0
23+ rhs : isDark ? darkColors : lightColors
1724 } ) ;
1825 const custom = isDark ? createTheme ( mergedColors , { dark : true } ) : createTheme ( mergedColors ) ;
1926 return {
@@ -288,12 +295,14 @@ function parseCssRules(cssText2) {
288295 }
289296 return result ;
290297}
291- function overrideThemes ( themes ) {
292- if ( themes . light !== void 0 ) {
293- $context ( ) . customThemes . light = themes . light ;
294- }
295- if ( themes . dark !== void 0 ) {
296- $context ( ) . customThemes . dark = themes . dark ;
298+ function overrideThemes ( config ) {
299+ const key = config . options ?. settingsKey ;
300+ const mode = enabledMode ( settingsForKey ( key ) ) ;
301+ if ( config . light !== void 0 && isModeEnabled ( false , mode ) ) {
302+ $context ( ) . customThemes . light = config . light ;
303+ }
304+ if ( config . dark !== void 0 && isModeEnabled ( true , mode ) ) {
305+ $context ( ) . customThemes . dark = config . dark ;
297306 }
298307 if ( typeof MarkEdit . editorView === "object" ) {
299308 updateTheme ( MarkEdit . editorView ) ;
0 commit comments