mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #3031 from Steve-Mcl/monaco0252
Update Monaco Editor to V0.25.2 (latest)
This commit is contained in:
@@ -153,19 +153,6 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
|
||||
function init(options) {
|
||||
|
||||
//Handles "Uncaught (in promise) Canceled: Canceled"
|
||||
//@see https://github.com/microsoft/monaco-editor/issues/2382
|
||||
//This is fixed in commit microsoft/vscode@49cad9a however it is not yet present monaco-editor
|
||||
//Remove the below addEventListener once monaco-editor V0.23.1 or greater is published
|
||||
window.addEventListener('unhandledrejection', function(evt) {
|
||||
if(evt && evt.reason && evt.reason.stack) {
|
||||
if (evt.reason.name === 'Canceled' && evt.reason.stack.indexOf('vendor/monaco/dist') >= 0) {
|
||||
evt.preventDefault();
|
||||
evt.stopImmediatePropagation();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Handles orphaned models
|
||||
//ensure loaded models that are not explicitly destroyed by a call to .destroy() are disposed
|
||||
RED.events.on("editor:close",function() {
|
||||
@@ -755,6 +742,15 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
var editorOptions = $.extend({}, editorSettings.options, options);
|
||||
editorOptions.language = convertAceModeToMonacoLang(options.mode);
|
||||
|
||||
//by default, set javascript editors to text 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
|
||||
//consts & lets to each other
|
||||
if(editorOptions.language == "javascript") {
|
||||
editorOptions._language = editorOptions.language;
|
||||
editorOptions.language = "text"
|
||||
}
|
||||
|
||||
//apply defaults
|
||||
if (!editorOptions.minimap) {
|
||||
editorOptions.minimap = {
|
||||
@@ -954,7 +950,9 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
var oldSelections = ed.getSelections();
|
||||
var oldPosition = ed.getPosition();
|
||||
oldValue = oldModel.getValue() || "";
|
||||
if(!oldModel.isDisposed()) { oldModel.dispose(); }
|
||||
try {
|
||||
if(!oldModel.isDisposed()) { oldModel.dispose(); }
|
||||
} catch (error) { }
|
||||
ed.setModel(null);
|
||||
newModel = monaco.editor.createModel((oldValue || ""), mode);
|
||||
ed.setModel(newModel);
|
||||
@@ -1222,16 +1220,20 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
|
||||
//as models are signleton, consts and let are avialable to other javascript instances
|
||||
//so when not focused, set editor mode to text temporarily to avoid multiple defs
|
||||
|
||||
|
||||
|
||||
if(editorOptions._language) {
|
||||
ed._mode = editorOptions._language;
|
||||
ed._tempMode = editorOptions.language;
|
||||
}
|
||||
|
||||
ed.onDidBlurEditorWidget(function() {
|
||||
if(isVisible(el) == false) {
|
||||
onVisibilityChange(false);
|
||||
onVisibilityChange(false, 0, el);
|
||||
}
|
||||
});
|
||||
|
||||
ed.onDidFocusEditorWidget(function() {
|
||||
onVisibilityChange(true, 10);
|
||||
onVisibilityChange(true, 10, el);
|
||||
});
|
||||
|
||||
function visibilityWatcher(element, callback) {
|
||||
@@ -1243,7 +1245,7 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
};
|
||||
var observer = new IntersectionObserver(function(entries, observer) {
|
||||
entries.forEach(function(entry) {
|
||||
callback(entry.intersectionRatio > 0, 5, entry);
|
||||
callback(entry.intersectionRatio > 0, 5, entry.target);
|
||||
});
|
||||
}, options);
|
||||
observer.observe(element);
|
||||
@@ -1254,7 +1256,7 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
watchTimer = setInterval(function() {
|
||||
let elVisible = isVisible(el);
|
||||
if(elVisible != elVisibleMem) {
|
||||
callback(elVisible, 100, element);
|
||||
callback(elVisible, 5, element);
|
||||
}
|
||||
elVisibleMem = elVisible;
|
||||
}, 100);
|
||||
@@ -1267,13 +1269,13 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
if(ed._mode == "javascript" && ed._tempMode == "text") {
|
||||
ed._tempMode = "";
|
||||
setTimeout(function() {
|
||||
if(el.parentElement) { //ensure el is still in DOM
|
||||
if(element.parentElement) { //ensure el is still in DOM
|
||||
ed.setMode('javascript', undefined, false);
|
||||
}
|
||||
}, delay);
|
||||
}, delay || 50);
|
||||
}
|
||||
} else if(ed._mode == "javascript") {
|
||||
if(el.parentElement) { //ensure el is still in DOM
|
||||
} else if(ed._mode == "javascript" && ed._tempMode != "text") {
|
||||
if(element.parentElement) { //ensure el is still in DOM
|
||||
ed.setMode('text', undefined, false);
|
||||
ed._tempMode = "text";
|
||||
}
|
||||
@@ -1282,14 +1284,6 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
|
||||
visibilityWatcher(el, onVisibilityChange);
|
||||
|
||||
//by default, set javascript editors to text mode.
|
||||
//when elemt becomes visible, it will be (re) set to javascript mode
|
||||
//this is to ensure multiple editors sharing the model dont presnet its
|
||||
//consts & lets to each other
|
||||
if(ed._mode == "javascript") {
|
||||
ed.setMode('text', undefined, false);
|
||||
ed._tempMode = "text";
|
||||
}
|
||||
|
||||
if (editorOptions.language === 'markdown') {
|
||||
$(el).addClass("red-ui-editor-text-container-toolbar");
|
||||
|
Reference in New Issue
Block a user