diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/theme.js b/packages/node_modules/@node-red/editor-api/lib/editor/theme.js index f2edf1059..918fed420 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/theme.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/theme.js @@ -246,7 +246,10 @@ module.exports = { theme.page = theme.page || {_:{}} theme.page._.scripts = scriptFiles.concat(theme.page._.scripts || []) } - themeSettings.monacoTheme = themePlugin.monacoTheme; + if(theme.codeEditor) { + theme.codeEditor.options = theme.codeEditor.options || {}; + theme.codeEditor.options.theme = themePlugin.monacoTheme; + } } activeThemeInitialised = true; } diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/code-editors/monaco.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/code-editors/monaco.js index 2a4da0e21..fbd9e7e06 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/code-editors/monaco.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/code-editors/monaco.js @@ -182,46 +182,34 @@ RED.editor.codeEditor.monaco = (function() { var editorSettings = RED.editor.codeEditor.settings || {}; var editorOptions = editorSettings.options || {}; - //if a theme is set and the plugin has a property monacoTheme, it should be the name of a pre-set theme or a monaco theme object + //if editorOptions.theme is an object (set in theme.js context()), use the plugin theme name as the monaco theme name + //if editorOptions.theme is a string, it should be the name of a pre-set theme, load that try { - if(RED.settings.editorTheme.theme && RED.settings.editorTheme.monacoTheme) { - if (typeof RED.settings.editorTheme.monacoTheme == "object") { - let themeThemeName = RED.settings.editorTheme.theme; - monacoThemes.push(themeThemeName);//add to list of loaded themes - monaco.editor.defineTheme(themeThemeName, RED.settings.editorTheme.monacoTheme); + const addTheme = function (themeThemeName, theme) { + if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) { + monacoThemes.push(themeThemeName); //add to list of loaded themes + monaco.editor.defineTheme(themeThemeName, theme); monaco.editor.setTheme(themeThemeName); userSelectedTheme = themeThemeName; - } else if (typeof RED.settings.editorTheme.monacoTheme == "string") { - let themeThemeName = RED.settings.editorTheme.monacoTheme; - let customTheme = 'vendor/monaco/dist/theme/' + editorOptions.theme + '.json'; - $.get(customTheme, function (theme) { - monacoThemes.push(themeThemeName);//add to list of loaded themes - if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) { - monaco.editor.defineTheme(themeThemeName, theme); - monaco.editor.setTheme(themeThemeName); - userSelectedTheme = themeThemeName; - } - }); + } + }; + if (editorOptions.theme) { + if (typeof editorOptions.theme == "object" && RED.settings.editorTheme.theme) { + let themeThemeName = editorOptions.theme.name || RED.settings.editorTheme.theme; + addTheme(themeThemeName, editorOptions.theme); + } else if (typeof editorOptions.theme == "string") { + let themeThemeName = editorOptions.theme; + if (!monacoThemes.includes(themeThemeName)) { + $.get('vendor/monaco/dist/theme/' + themeThemeName + '.json', function (theme) { + addTheme(themeThemeName, theme); + }); + } } } } catch (error) { console.warn(error); } - //if a theme is explicitally set, load & choose that - if (editorOptions.theme) { - if (!monacoThemes.includes(editorOptions.theme)) { - let customTheme = 'vendor/monaco/dist/theme/' + editorOptions.theme + '.json'; - $.get(customTheme, function (theme) { - monacoThemes.push(editorOptions.theme);//add to list of loaded themes - if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) { - monaco.editor.defineTheme(editorOptions.theme, theme); - monaco.editor.setTheme(editorOptions.theme); - userSelectedTheme = editorOptions.theme; - } - }); - } - } //Helper function to simplify snippet setup function createMonacoCompletionItem(label, insertText, documentation, range, kind) {