@@ -1432,8 +1432,8 @@ const loadConfig = async (
14321432 changingContent = false ;
14331433} ;
14341434
1435- const applyConfig = async ( newConfig : Partial < Config > , reload = false ) => {
1436- const currentConfig = getConfig ( ) ;
1435+ const applyConfig = async ( newConfig : Partial < Config > , reload = false , oldConfig ?: Config ) => {
1436+ const currentConfig = oldConfig || getConfig ( ) ;
14371437 const combinedConfig : Config = { ...currentConfig , ...newConfig } ;
14381438 if ( reload ) {
14391439 await updateEditors ( editors , getConfig ( ) ) ;
@@ -1518,24 +1518,20 @@ const applyConfig = async (newConfig: Partial<Config>, reload = false) => {
15181518 } ) ;
15191519 }
15201520
1521- let shouldReloadEditors = false ;
15221521 const editorConfig = {
15231522 ...getEditorConfig ( newConfig as Config ) ,
15241523 ...getFormatterConfig ( newConfig as Config ) ,
15251524 } ;
1526- const hasEditorConfig = Object . values ( editorConfig ) . some ( ( value ) => value != null ) ;
1527- if ( hasEditorConfig ) {
1528- for ( const key in editorConfig ) {
1529- if (
1530- key in newConfig &&
1531- ( editorConfig as any ) [ key ] !== ( currentEditorConfig as any ) [ key ] &&
1532- ! key . toLowerCase ( ) . includes ( 'theme' )
1533- ) {
1534- shouldReloadEditors = true ;
1535- break ;
1536- }
1525+
1526+ const hasEditorConfig = Object . keys ( editorConfig ) . some ( ( k ) => k in newConfig ) ;
1527+ let shouldReloadEditors = ( ( ) => {
1528+ if ( newConfig . editor != null && ! ( newConfig . editor in editors . markup ) ) return true ;
1529+ if ( newConfig . mode != null ) {
1530+ if ( newConfig . mode !== 'result' && editors . markup . isFake ) return true ;
1531+ if ( newConfig . mode !== 'codeblock' && editors . markup . codejar ) return true ;
15371532 }
1538- }
1533+ return false ;
1534+ } ) ( ) ;
15391535 if ( 'configureTailwindcss' in editors . markup ) {
15401536 if ( newConfig . processors ?. includes ( 'tailwindcss' ) ) {
15411537 editors . markup . configureTailwindcss ?.( true ) ;
@@ -1550,6 +1546,12 @@ const applyConfig = async (newConfig: Partial<Config>, reload = false) => {
15501546 }
15511547 if ( shouldReloadEditors ) {
15521548 await reloadEditors ( combinedConfig ) ;
1549+ } else if ( hasEditorConfig ) {
1550+ currentEditorConfig = {
1551+ ...getEditorConfig ( combinedConfig ) ,
1552+ ...getFormatterConfig ( combinedConfig ) ,
1553+ } ;
1554+ getAllEditors ( ) . forEach ( ( editor ) => editor . changeSettings ( currentEditorConfig ) ) ;
15531555 }
15541556
15551557 parent . dispatchEvent ( new Event ( customEvents . ready ) ) ;
@@ -5538,14 +5540,6 @@ const createApi = (): API => {
55385540 const shouldRun =
55395541 newConfig . mode != null && newConfig . mode !== 'editor' && newConfig . mode !== 'codeblock' ;
55405542 const shouldReloadCompiler = shouldRun && compiler . isFake ;
5541- const shouldReloadCodeEditors = ( ( ) => {
5542- if ( newConfig . editor != null && ! ( newConfig . editor in editors . markup ) ) return true ;
5543- if ( newConfig . mode != null ) {
5544- if ( newConfig . mode !== 'result' && editors . markup . isFake ) return true ;
5545- if ( newConfig . mode !== 'codeblock' && editors . markup . codejar ) return true ;
5546- }
5547- return false ;
5548- } ) ( ) ;
55495543 const isContentOnlyChange = compareObjects (
55505544 newConfig ,
55515545 currentConfig as Record < string , any > ,
@@ -5570,10 +5564,7 @@ const createApi = (): API => {
55705564 if ( shouldReloadCompiler ) {
55715565 await reloadCompiler ( newAppConfig ) ;
55725566 }
5573- if ( shouldReloadCodeEditors ) {
5574- await createEditors ( newAppConfig ) ;
5575- }
5576- await applyConfig ( newConfig , /* reload = */ true ) ;
5567+ await applyConfig ( newConfig , /* reload = */ true , currentConfig ) ;
55775568 const content = getContentConfig ( newConfig as Config ) ;
55785569 const hasContent = Object . values ( content ) . some ( ( value ) => value != null ) ;
55795570 if ( hasContent ) {
0 commit comments