mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3084 from Steve-Mcl/theme-monaco-theme
Permit plugin theme to theme monaco editor
This commit is contained in:
commit
893ef227d4
@ -253,6 +253,9 @@ 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 || [])
|
||||||
}
|
}
|
||||||
|
if(theme.codeEditor) {
|
||||||
|
theme.codeEditor.options = Object.assign({}, themePlugin.monacoOptions, theme.codeEditor.options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activeThemeInitialised = true;
|
activeThemeInitialised = true;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
var initialised = false;
|
var initialised = false;
|
||||||
const type = "monaco";
|
const type = "monaco";
|
||||||
const monacoThemes = ["vs","vs-dark","hc-black"]; //TODO: consider setting hc-black autmatically based on acessability?
|
const monacoThemes = ["vs","vs-dark","hc-black"]; //TODO: consider setting hc-black autmatically based on acessability?
|
||||||
|
let userSelectedTheme;
|
||||||
|
|
||||||
//TODO: get from externalModules.js For now this is enough for feature parity with ACE (and then some).
|
//TODO: get from externalModules.js For now this is enough for feature parity with ACE (and then some).
|
||||||
const knownModules = {
|
const knownModules = {
|
||||||
@ -181,18 +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 (editorOptions.theme) {
|
//if editorOptions.theme is an object (set in theme.js context()), use the plugin theme name as the monaco theme name
|
||||||
if (!monacoThemes.includes(editorOptions.theme)) {
|
//if editorOptions.theme is a string, it should be the name of a pre-set theme, load that
|
||||||
var customTheme = 'vendor/monaco/dist/theme/' + editorOptions.theme + '.json';
|
try {
|
||||||
$.get(customTheme, function (theme) {
|
const addTheme = function (themeThemeName, theme) {
|
||||||
monacoThemes.push(editorOptions.theme);//add to list of loaded themes
|
|
||||||
if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) {
|
if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) {
|
||||||
monaco.editor.defineTheme(editorOptions.theme, theme);
|
monacoThemes.push(themeThemeName); //add to list of loaded themes
|
||||||
monaco.editor.setTheme(editorOptions.theme);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//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) {
|
||||||
@ -744,6 +761,10 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
var editorOptions = $.extend({}, editorSettings.options, options);
|
var editorOptions = $.extend({}, editorSettings.options, options);
|
||||||
editorOptions.language = convertAceModeToMonacoLang(options.mode);
|
editorOptions.language = convertAceModeToMonacoLang(options.mode);
|
||||||
|
|
||||||
|
if(userSelectedTheme) {
|
||||||
|
editorOptions.theme = userSelectedTheme;//use user selected theme for this session
|
||||||
|
}
|
||||||
|
|
||||||
//by default, set javascript editors to text mode.
|
//by default, set javascript editors to text mode.
|
||||||
//when element becomes visible, it will be (re) set to javascript mode
|
//when element becomes visible, it will be (re) set to javascript mode
|
||||||
//this is to ensure multiple editors sharing the model dont present its
|
//this is to ensure multiple editors sharing the model dont present its
|
||||||
@ -1169,7 +1190,10 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
return { row: p.lineNumber-1, column: p.column-1 };
|
return { row: p.lineNumber-1, column: p.column-1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
ed.setTheme = monaco.editor.setTheme;
|
ed.setTheme = function(theme) {
|
||||||
|
monaco.editor.setTheme(theme);
|
||||||
|
userSelectedTheme = theme;//remember users choice for this session
|
||||||
|
}
|
||||||
|
|
||||||
ed.on = function (name, cb) {
|
ed.on = function (name, cb) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user