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 = theme.page || {_:{}}
theme.page._.scripts = scriptFiles.concat(theme.page._.scripts || []) 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; activeThemeInitialised = true;
} }

View File

@ -182,46 +182,34 @@ RED.editor.codeEditor.monaco = (function() {
var editorSettings = RED.editor.codeEditor.settings || {}; var editorSettings = RED.editor.codeEditor.settings || {};
var editorOptions = editorSettings.options || {}; 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 { try {
if(RED.settings.editorTheme.theme && RED.settings.editorTheme.monacoTheme) { const addTheme = function (themeThemeName, theme) {
if (typeof RED.settings.editorTheme.monacoTheme == "object") { if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) {
let themeThemeName = RED.settings.editorTheme.theme; monacoThemes.push(themeThemeName); //add to list of loaded themes
monacoThemes.push(themeThemeName);//add to list of loaded themes monaco.editor.defineTheme(themeThemeName, theme);
monaco.editor.defineTheme(themeThemeName, RED.settings.editorTheme.monacoTheme);
monaco.editor.setTheme(themeThemeName); monaco.editor.setTheme(themeThemeName);
userSelectedTheme = 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'; if (editorOptions.theme) {
$.get(customTheme, function (theme) { if (typeof editorOptions.theme == "object" && RED.settings.editorTheme.theme) {
monacoThemes.push(themeThemeName);//add to list of loaded themes let themeThemeName = editorOptions.theme.name || RED.settings.editorTheme.theme;
if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) { addTheme(themeThemeName, editorOptions.theme);
monaco.editor.defineTheme(themeThemeName, theme); } else if (typeof editorOptions.theme == "string") {
monaco.editor.setTheme(themeThemeName); let themeThemeName = editorOptions.theme;
userSelectedTheme = themeThemeName; if (!monacoThemes.includes(themeThemeName)) {
} $.get('vendor/monaco/dist/theme/' + themeThemeName + '.json', function (theme) {
}); addTheme(themeThemeName, theme);
});
}
} }
} }
} catch (error) { } catch (error) {
console.warn(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 //Helper function to simplify snippet setup
function createMonacoCompletionItem(label, insertText, documentation, range, kind) { function createMonacoCompletionItem(label, insertText, documentation, range, kind) {