1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

use codeEditor.options.theme

This commit is contained in:
Steve-Mcl 2021-07-26 21:02:11 +01:00
parent d7a2fc2be4
commit 8a1d81989b
2 changed files with 23 additions and 32 deletions

View File

@ -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;
}

View File

@ -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) {