Merge pull request #3015 from Steve-Mcl/monaco-beta-bug-fix

Patches for Monaco editor
This commit is contained in:
Nick O'Leary
2021-06-28 15:27:27 +01:00
committed by GitHub
3 changed files with 225 additions and 49 deletions

View File

@@ -2776,7 +2776,6 @@ var buildingEditDialog = false;
$("#node-dialog-cancel").trigger("click");
$("#node-config-dialog-cancel").trigger("click");
});
//console.log("packages/node_modules/@node-red/editor-client/src/js/ui/editor.js ? init()") //TODO: Remove
RED.editor.codeEditor.init();
},
edit: showEditDialog,

View File

@@ -25,11 +25,14 @@
function .selection.getRange();
property .session //the editor object
function .session.insert = function(position, text)
function .setReadOnly(readOnly)
property .renderer = {};
function .renderer.updateFull()
function setMode(mode, cb)
function getRange();
function replace(range, text)
function selectAll
function clearSelection
function getSelectedText()
function destroy()
function resize()
@@ -120,7 +123,7 @@ RED.editor.codeEditor.monaco = (function() {
const def = modulesCache[libPath];
if( def ) {
if(!preloadOnly) {
loadedLibs.JS[libModule] = monaco.languages.typescript.javascriptDefaults.addExtraLib(def, `file://types/${libPackage}/${libModule}/index.d.ts`);
loadedLibs.JS[libModule] = monaco.languages.typescript.javascriptDefaults.addExtraLib(def, "file://types/" + libPackage + "/" + libModule + "/index.d.ts");
}
if(cb) {
setTimeout(function() {
@@ -133,7 +136,7 @@ RED.editor.codeEditor.monaco = (function() {
.done(function(data) {
modulesCache[libPath] = data;
if(!preloadOnly) {
loadedLibs.JS[libModule] = monaco.languages.typescript.javascriptDefaults.addExtraLib(data, `file://types/${libPackage}/${libModule}/index.d.ts`);
loadedLibs.JS[libModule] = monaco.languages.typescript.javascriptDefaults.addExtraLib(data, "file://types/" + libPackage + "/" + libModule + "/index.d.ts");
}
if(cb) { cb(null, _module) }
})
@@ -563,7 +566,7 @@ RED.editor.codeEditor.monaco = (function() {
createMonacoCompletionItem("node.send", 'node.send(${1:msg});','async send a msg to the next node',range),
createMonacoCompletionItem("node.send (multiple)", 'var ${1:msg1} = {payload:${2:1}};\nvar ${3:msg2} = {payload:${4:2}};\nnode.send([[${1:msg1}, ${3:msg2}]]);','send 1 or more messages out of 1 output',range),
createMonacoCompletionItem("node.send (multiple outputs)", 'var ${1:msg1} = {payload:${2:1}};\nvar ${3:msg2} = {payload:${4:2}};\nnode.send([${1:msg1}, ${3:msg2}]);','send more than 1 message out of multiple outputs',range),
createMonacoCompletionItem("node.status", 'node.status({fill:"${1:red}",shape:"${2:ring}",text:"${3:error}"});','Set the status icon and text underneath the function node',range),
createMonacoCompletionItem("node.status", 'node.status({fill:"${1|red,green,yellow,blue,grey|}",shape:"${2|ring,dot|}",text:"${3:message}"});','Set the status icon and text underneath the function node',range),
createMonacoCompletionItem("get (node context)", 'context.get("${1:name}");','Get a value from node context',range),
createMonacoCompletionItem("set (node context)", 'context.set("${1:name}", ${1:value});','Set a value in node context',range),
createMonacoCompletionItem("get (flow context)", 'flow.get("${1:name}");','Get a value from flow context',range),
@@ -645,6 +648,7 @@ RED.editor.codeEditor.monaco = (function() {
strictPropertyInitialization: true,
strictFunctionTypes: true,
strictBindCallApply: true,
useDefineForClassFields: true,//permit class static fields with private name to have initializer
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
module: monaco.languages.typescript.ModuleKind.CommonJS,
typeRoots: ["types"],
@@ -666,6 +670,7 @@ RED.editor.codeEditor.monaco = (function() {
2307, //Cannot find module 'xxx' or its corresponding type declarations
2322, //Type 'unknown' is not assignable to type 'string'
2339, //property does not exist on
2345, //Argument of type xxx is not assignable to parameter of type 'DateTimeFormatOptions'
7043, //i forget what this one is,
80001, //Convert to ES6 module
80004, //JSDoc types may be moved to TypeScript types.
@@ -881,7 +886,8 @@ RED.editor.codeEditor.monaco = (function() {
if(!extraModuleLibs || extraModuleLibs.length == 0) {
loadedLibs.JS[id] = monaco.languages.typescript.javascriptDefaults.addExtraLib(" ", file);
} else {
var loadList = [...extraModuleLibs];
var loadList = [];
Array.prototype.push.apply(loadList, extraModuleLibs);//Use this instead of spread operator to prevent IE syntax error
var loadExtraModules = {};
for (let index = 0; index < extraModuleLibs.length; index++) {
const lib = extraModuleLibs[index];
@@ -990,6 +996,10 @@ RED.editor.codeEditor.monaco = (function() {
_executeEdits(this,[op]);
}
ed.setReadOnly = function setReadOnly(readOnly) {
ed.updateOptions({ readOnly: readOnly })
}
ed.session.replace = function replace(range, text) {
var op = { range: range, text: text, forceMoveMarkers: true };
_executeEdits(this,[op]);
@@ -1006,11 +1016,20 @@ RED.editor.codeEditor.monaco = (function() {
}
}
ed.selectAll = function selectAll() {
const range = ed.getModel().getFullModelRange();
ed.setSelection(range);
}
ed.clearSelection = function clearSelection() {
ed.setPosition({column:1,lineNumber:1});
}
ed.getSelectedText = function getSelectedText() {
return ed.getModel().getValueInRange(ed.getSelection());
}
ed.insertSnippet = function editer_insertSnippet(s) {
ed.insertSnippet = function insertSnippet(s) {
//https://github.com/microsoft/monaco-editor/issues/1112#issuecomment-429580604
//no great way of triggering snippets!
let contribution = ed.getContribution("snippetController2");